0

I have the following code on a button

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js")} 

if (({!Service_Call__c.Incomplete_Parts_Count__c} > 0))
{
alert( "Error: One or more parts on this call have not been completely filled out. Update parts before releasing." ); 
}
else {
var newRecords = []; 
var c = new sforce.SObject("Service_Call__c");
c.id ="{!Service_Call__c.Id}"; 
c.Release__c = true;
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();
}

It works as long as there is some type of number in that field, but sometimes it is just null and it causes this error. I've tried to manipulate my if statement to include the null, but I don't really know how. Any help would be appreciated. Thanks!

  • Does it work if you change Service_Call__c.Incomplete_Parts_Count__c to BLANKVALUE(Service_Call__c.Incomplete_Parts_Count__c, 0)? – Adrian Larson May 24 '18 at 17:17
  • It worked now if the field was null, but gave an error that says "BLANKVALUE not defined" when there was a number in the field – ad_rey May 24 '18 at 17:31
0

When possible, don't jump in and out of JavaScript; you can use normal formulas just like you would in Visualforce, which can reduce the likelihood of errors:

if( {!BLANKVALUE(Service_Call__c.Incomplete_Parts_Count__c,0) > 0} )

Upon evaluation, the JavaScript will be converted to a simple:

if( true )

or

if( false )

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.