Saturday, 8 July 2017

How to use comparatiors operator in java script button code ?

Hi All,

This post is just to help you to use comparatiors operator (Greater than  > and less than <) effectively in Java script code.

I did face some issue while using,

Say the case record is having Absolute_Total_Exception_Amount_USD__c as 50,340.
{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}
{!requireScript("/soap/ajax/26.0/apex.js")}

alert('print-'+{!Case.Absolute_Total_Exception_Amount_USD__c}); -- it will Print50
alert('print-'+"{!Case.Absolute_Total_Exception_Amount_USD__c}"); - It will print 50,340
var amount =  "{!Case.Absolute_Total_Exception_Amount_USD__c}";

if(amount  > "120000"){
alert('webservice method');
}
else{
alert('Pagemethod');
}

Always else block will get executed, Pagemethod alert will come.

The correct approach will be
var amount = {!VALUE(TEXT(Case.Absolute_Total_Exception_Amount_USD__c))};
alert('Pagemethod-4-'+amount );
if(amount  > "120000"){
alert('webservice method');
}
else{
alert('Pagemethod');
}

No comments: