+ Start a Discussion
Del_SantosDel_Santos 

Help with Javascript button

Hi,

 

I created a javascript button to open a vf page if {!Quote.Installation_Address_2__c} is not blank but encountering an error. Im not sure how to define a blank value. i am encountering an invalid token issue.

 

 

==========================================

here's the code

 

if ({!Quote.Installation_Address_2__c}!= null)
{
window.parent.location.href="apex/Generate_Endorsement_Letter_B?id={!Quote.Id}";
}
else {
alert("Site B Installation Address is Missing!");
}

 

Thanks!

Del

Avidev9Avidev9

You have to do a blank check when using a merge field, the preprocessor will replace the merge fields with actual values and after that js will run. So eventually it should be blank if value is null.

 

Try somehting like this

 

if ('{!JSENCODE(Quote.Installation_Address_2__c)}'!= '') {
    window.parent.location.href = "apex/Generate_Endorsement_Letter_B?id={!Quote.Id}";
} else {
    alert("Site B Installation Address is Missing!");
}

 

 

Del_SantosDel_Santos

Hi Avi,

 

tried the code, now the page is coming, however, the page is coming out regardless the field is blank or not. 

 

 

Many tHanks!

Del

 

Avidev9Avidev9
Try about debugging the same by adding
alert('{!JSENCODE(Quote.Installation_Address_2__c)}');
or
console.log('{!JSENCODE(Quote.Installation_Address_2__c)}');

Del_SantosDel_Santos

got the problem. the condition did not work field is a formula type. hmm, now i need to check for substitute.

Del_SantosDel_Santos

anyone have suggestions? i need to convert this formula field in to text from the code.

Avidev9Avidev9
Have you given try to TEXT() function ?