+ Start a Discussion
jalexanderjalexander 

Extending my "Custom Javascript Button" and getting error "Undefined"?

I have the following javascript button on my Quote object that is giving me an "undefined" error when clicked:
User-added image

Here is the code:
{!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")}

try{
var queryResult = sforce.connection.query(
"SELECT Id, XX_ORD1__Status__c, MSA_Agreement__c, CAA_Agreement__c, SYS_Account_Credit_Application__c, SYS_Site_Contact_check__c, SYS_IT_Contact_check__c" +
"FROM XX_ORD1__Quote__c" +
"WHERE Id = '{!XX_ORD1__Quote__c.Id}'"
);

var quote = queryResult.get("records");

if(quote.XX_ORD1__Status__c != 'Approved'){
alert("Approval Status has to be Approved before you can create the BSO.");
}

else if(quote.MSA_Agreement__c === null){
alert("No MSA found! You have to attach the MSA Agreement to the Quote before you can create the BSO.");
}

else if(quote.CAA_Agreement__c === null && quote.SYS_Account_Credit_Application__c !== 'No'){
alert("No CAA found! You have to attach the CAA Agreement to the Quote before you can create the BSO.");
}

else if(quote.SYS_Site_Contact_check__c === null){
alert("No Site Contact found! You have to have a Site Contact on the Location before you can create the BSO.");
}

else if(quote.SYS_IT_Contact_check__c === null){
alert("No IT Contact found! You have to have a IT Contact on the Location before you can create the BSO.");
}
else{
location.replace(
"/apex/echosign_dev1__AgreementTemplateProcess?masterid={!XX_ORD1__Quote__c.Id}"
);
}
}
catch(e){
alert("An Error has Occurred. Error:" + e.message);
}
Any ideas on what is causing this and how to tweak my code to fix?
 
Alain CabonAlain Cabon
Hi,

You need at least one space or new line around FROM and WHERE (before and after).

var queryResult = sforce.connection.query( "SELECT Id, XX_ORD1__Status__c, MSA_Agreement__c, CAA_Agreement__c, SYS_Account_Credit_Application__c, SYS_Site_Contact_check__c, SYS_IT_Contact_check__c"
+ " FROM XX_ORD1__Quote__c"
+ " WHERE Id = '{!XX_ORD1__Quote__c.Id}'" );