You need to sign in to do that
Don't have an account?
Esmeralda Canoog 3
Add onclick javascript "custom button" in visualforce page.
I have a custom button created in the object called CM and this button execute javascript, content source is onclick javascript: Name of the button is Print and "Print_CM" here is a VF page. See below
CM_Status__c ,'Cancelled')} && !{!ISPICKVAL( Credit_Memo__c.SFCM_Status__c ,'Reversed')} && !{!ISPICKVAL( Credit_Memo__c.SFCM_Status__c ,'Disapproved')})
{
window.location.href = "https://" + window.location.host + "/apex/Print_CM?id=" + "{!Credit_Memo__c.Id}";
} else {
alert("Error: This Credit Memo cannot be printed.")
}
Now I'm trying to add this button in my existing VF page and let's call it "CM View".
I'm trying to add it as <apex:commandbutton but not sure how to do it. I know that I need to add something from the existing controller to call it in the CM View VF page, but I'm not sure how to do it well.
Any help will be much appreciated.
Thanks in advance guys :)
CM_Status__c ,'Cancelled')} && !{!ISPICKVAL( Credit_Memo__c.SFCM_Status__c ,'Reversed')} && !{!ISPICKVAL( Credit_Memo__c.SFCM_Status__c ,'Disapproved')})
{
window.location.href = "https://" + window.location.host + "/apex/Print_CM?id=" + "{!Credit_Memo__c.Id}";
} else {
alert("Error: This Credit Memo cannot be printed.")
}
Now I'm trying to add this button in my existing VF page and let's call it "CM View".
I'm trying to add it as <apex:commandbutton but not sure how to do it. I know that I need to add something from the existing controller to call it in the CM View VF page, but I'm not sure how to do it well.
Any help will be much appreciated.
Thanks in advance guys :)
Add below code in your VF page and replace Credit_Memo__c api name with your variable created in controller class.
<script>
function executelogic(){
if({!Credit_Memo__c.CM_Status__c =='Cancelled' && {!Credit_Memo__c.SFCM_Status__c!=Reversed'} && {!Credit_Memo__c.SFCM_Status__c!=Disapproved'})
{
window.location.href = "https://" + window.location.host + "/apex/Print_CM?id=" + "{!Credit_Memo__c.Id}";
return false;
} else {
alert("Error: This Credit Memo cannot be printed.")
return false;
}
}
</script>
In case if you have any concerns, I am avilable on https://www.uberconference.com/nawaleprakash so we can do screen share and resolve your issue.
Thanks
All Answers
<apex:commandbutton onclick="return executelogic()" .../>
<script>
function executelogic(){
CM_Status__c ,'Cancelled')} && !{!ISPICKVAL( Credit_Memo__c.SFCM_Status__c ,'Reversed')} && !{!ISPICKVAL( Credit_Memo__c.SFCM_Status__c ,'Disapproved')})
{
window.location.href = "https://" + window.location.host + "/apex/Print_CM?id=" + "{!Credit_Memo__c.Id}";
return false;
} else {
alert("Error: This Credit Memo cannot be printed.")
return false;
}
}
</script>
Tried it but it says
Incorrect parameter type for function 'ISPICKVAL()'. Expected Picklist, received Text. Thanks
The ISPICKVAL() is only used for picklists data type field to compare value not for text data type field value. I am not sure which type of above fields, can you please verify field data types and then apply is ISPICKVAL() for only picklists.
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
if(!{!ISPICKVAL( Credit_Memo__c.SFCM_Status__c ,'Error')} && !{!ISPICKVAL( Credit_Memo__c.SFCM_Status__c ,'Cancelled')} && !{!ISPICKVAL( Credit_Memo__c.SFCM_Status__c ,'Reversed')} && !{!ISPICKVAL( Credit_Memo__c.SFCM_Status__c ,'Disapproved')})
{
window.location.href = "https://" + window.location.host + "/apex/Print_CM?id=" + "{!Credit_Memo__c.Id}";
} else {
alert("Error: This Credit Memo cannot be printed.")
}
Thank you.
Add below code in your VF page and replace Credit_Memo__c api name with your variable created in controller class.
<script>
function executelogic(){
if({!Credit_Memo__c.CM_Status__c =='Cancelled' && {!Credit_Memo__c.SFCM_Status__c!=Reversed'} && {!Credit_Memo__c.SFCM_Status__c!=Disapproved'})
{
window.location.href = "https://" + window.location.host + "/apex/Print_CM?id=" + "{!Credit_Memo__c.Id}";
return false;
} else {
alert("Error: This Credit Memo cannot be printed.")
return false;
}
}
</script>
In case if you have any concerns, I am avilable on https://www.uberconference.com/nawaleprakash so we can do screen share and resolve your issue.
Thanks
<script>
function executelogic(){
if({!Credit_Memo__c.SFCM_Status__c =='Cancelled'})
{
window.location.href = "https://" + window.location.host + "/apex/Print_CM?id=" + "{!Credit_Memo__c.Id}";
return false;
} else {
alert("Error: This Credit Memo cannot be printed.")
return false;
}
}
</script>
This is working,but there's a problem when I tried to make it work with the "reversed status" or when I include other values. Do you know how to add multiple values? tried 2 value for the mean time below but its not working tried what you have posted a while ago but its not working. It only works with one value: Below is not working as well (2 values)
<script>
function executelogic(){
if({!Credit_Memo__c.SFCM_Status__c =='Cancelled'} && {!Credit_Memo__c.SFCM_Status__c == 'Reversed'})
{
window.location.href = "https://" + window.location.host + "/apex/Print_CM?id=" + "{!Credit_Memo__c.Id}";
return false;
} else {
alert("Error: This Credit Memo cannot be printed.")
return false;
}
}
</script>
You need to use or "||" operator in if conidtion to work for both value.
if({!Credit_Memo__c.SFCM_Status__c =='Cancelled'} || {!Credit_Memo__c.SFCM_Status__c == 'Reversed'})