1

I tried adding a custom button on the page and I received the error saying "Unexpected Number". Here is the code.

The OrderApi__Receipt__c.OrderApi__Balance__c is a formula field of type currency. I did try adding $ before 0.00 but it still threw the same error

else if ({!OrderApi__Receipt__c.OrderApi__Is_Refund__c
} && {!OrderApi__Receipt__c.OrderApi__Balance__c
    } = 0.00) {
        alert('Refund processed. DO you wish to continue');
    } else if ({!OrderApi__Receipt__c.OrderApi__Is_Refund__c
        }) {
            //alert('in refund loop'); 
            rec.OrderApi__Process_Refund__c = true;
            sforce.connection.update([rec]);
        }location.reload(true);
1
  • Though this comment is not related to this question but it is observed that you are not selecting answers as accepted to your questions though your purpose got resolved and members are devoting their time and effort to solve your issue. Accepting answers will help to identity the best answers and person got reputation helping your issues, that's the way community works – Santanu Boral Jun 4 '17 at 21:19
0

Currency formula or field already returns currency indicator along with the value.

So, even amount is 0.00, it will return $0.00;

Better, trim off the $ and verify the amount as below.

var amountStr = '{!OrderApi__Receipt__c.OrderApi__Balance__c}';
var actualValue = amountStr.substr(1, amountStr.length-1);

if(actualValue == 0.00)
{
     alert('Final amount is zero');
}
else
{
    alert('Final amount is not zero');
}

So, final code will look like this:

var amountStr = '{!OrderApi__Receipt__c.OrderApi__Balance__c}';
var actualValue = amountStr.substr(1, amountStr.length-1);

else if('{!OrderApi__Receipt__c.OrderApi__Is_Refund__c}'&& actualValue ==0.00)
{ 
   alert('Refund processed. DO you wish to continue'); 
}else if('{!OrderApi__Receipt__c.OrderApi__Is_Refund__c}') { 
   //alert('in refund loop'); 
rec.OrderApi__Process_Refund__c = true; 
    sforce.connection.update([rec]); 
} 
location.reload(true);
3
  • I did try that and I get the following error : " Invalid left hand side in assignment" – user43146 Jun 4 '17 at 19:59
  • use actualValue ==0.00 in if condition – Santanu Boral Jun 4 '17 at 20:06
  • This code assumes the user is configured for the United States locale and may break for other locales. – sfdcfox Jun 5 '17 at 1:15
2

You can use the formula syntax as an alternative:

else if( {!AND( OrderApi__Receipt__c.OrderApi__Is_Refund__c,
           OrderApi__Receipt__c.OrderApi__Balance__c = 0) } ) {

Using this syntax allows you to get compiler errors instead of having to troubleshoot JavaScript. This means you no longer have to trim off the $ or worry about locale errors, and also supports multicurrency if you decide to use it in the future.

6
  • if I omit the first condition and verify this: if('{!OrderApi__Receipt__c.OrderApi__Balance__c}' = 0) , it will give invalid left side assignment error, also if I use, if('{!OrderApi__Receipt__c.OrderApi__Balance__c}' == 0) , it will return false always, as it returns $0.00 for currency type formula field – Santanu Boral Jun 5 '17 at 1:38
  • for that sake of testing I have created a formula field in Opportunity object referring Amount of the Opportunity – Santanu Boral Jun 5 '17 at 1:40
  • @SantanuBoral You mis-read the answer: the entire thing is unquoted and within the merge field. Doing this eliminates any need to parse anything in JavaScript whatsoever, as JavaScript will only see else if( true ) or else if( false ). – sfdcfox Jun 5 '17 at 1:43
  • Can you please run this code at your DE and let me know your findings: alert('{!Opportunity.Final_Amount__c}'); if('{!Opportunity.Final_Amount__c}' == 0) { alert('Final amount is zero'); } else { alert('Final amount is not zero'); } – Santanu Boral Jun 5 '17 at 1:55
  • where Final_Amount__c is currency formula related to Amount field – Santanu Boral Jun 5 '17 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.