function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nelum FernandoNelum Fernando 

Unexpected token >

Hi,

I'm trying to excute the below javascript (without a real understanding of javascript) on a custom button within a Opportunity object. But it ends up with an error "Unexpected token >" Appreciate any help to sort this out. Thanks 


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


if('{!Quote.Status}'<>"Approved"){
alert("Quote needs to be approved ");
}
else{
window.open('/apex/echosign_dev1__AgreementTemplateProcess?masterid={!Opportunity.Id}&templateId=a0X2000000ARCFK');
}
Best Answer chosen by Nelum Fernando
BALAJI CHBALAJI CH
Hi Nelum,

Good to listen that its working for you.
The code which you put in the question is perfect if the Button is on Quote Object. But when you said that Button is on Opportunity Object, we cannot directly use "{!Quote.Status}" to get the Quotes's Status value. So, we need to retrieve the Opportunity's related Quote record to get the value of Status in that Quote record.
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

//Below Line is to retrieve Data from Salesforce using sforce connection by passing a query ansd stores in result. In the query, we are getting Quote record of the Opportunity on which button is clicked.
var result= sforce.connection.query("select id, Status from Quote where opportunityid ='{!Opportunity.Id}'");

//This line gets the records into Array form from result and stors in records.
var records = result.getArray("records");

//Since we have only one quote record, we can use records[0] to get values of that record.
if(records[0].Status != "Approved")
{
alert("Quote needs to be approved ");
}

else{
window.open('/apex/echosign_dev1__AgreementTemplateProcess?masterid={!Opportunity.Id}&templateId=a0X2000000ARCFK');
}
Let us know if you have more questions.
Please mark a Best answer to close this thread so that it can be useful to others if required.

Best Regards,
BALAJI

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try below code and let us know if that will help you
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}


if('{!Quote.Status}' != "Approved")
{
	alert("Quote needs to be approved ");
}
else
{
window.open('/apex/echosign_dev1__AgreementTemplateProcess?masterid={!Opportunity.Id}&templateId=a0X2000000ARCFK');
}


 
BALAJI CHBALAJI CH
Hi Nelum Fernando,

In Javascript, the comparison operator for 'Not Equals' should be used as '!=' instead of '<>'. Replacing the operator <> with != should work your code.
Please try below modified code.
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}


if('{!Quote.Status}'!="Approved"){
alert("Quote needs to be approved ");
}
else{
window.open('/apex/echosign_dev1__AgreementTemplateProcess?masterid={!Opportunity.Id}&templateId=a0X2000000ARCFK');
}
Let me know if that helps you.

Best Regards,
BALAJI

 
Nelum FernandoNelum Fernando
Hi Balaji,

Thanks for the reply. It eliminated the unexpectd token error, but always generating the alert even if the quote is in approved status.
BALAJI CHBALAJI CH
Hi Nelum,

I just double checked in my Org and its working fine.
Can you please recheck the code and try sharing the screenshot. Also can you confirm the Type of the Button is Details Page Button.

Best Regards,
BALAJI
Nelum FernandoNelum Fernando
Yes it's a detail page button. But the button is in opportunity object while the status is in quote object.it's a picklist value. I'm not sure whether it should have any impact though

CodeQuoteError
BALAJI CHBALAJI CH
Hi Nelum,

You mean to say that button is on Opportunity Object and when clicked, it should check it's related Quote's Status value and perform action accordingly. This can be done if Opportunity has One Quote only.
But I have a doubt, what if the opportunity has multiple quotes ? Which Quote's Status value should it check to perform action.

Please find below modified code which works fine if Opportunity has Single Quote.
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

var result= sforce.connection.query("select id, Status from Quote where opportunityid ='{!Opportunity.Id}'");

var records = result.getArray("records");
if(records[0].Status != "Approved")
{
alert("Quote needs to be approved ");
}

else{
window.open('/apex/echosign_dev1__AgreementTemplateProcess?masterid={!Opportunity.Id}&templateId=a0X2000000ARCFK');
}
Let Me know if that works for you.

Best Regards,
BALAJI
Nelum FernandoNelum Fernando
Hi Balaji,

It is working , we only do one quote per opportunity so this is perfect for us. Thank you very much for sedning this.
If it's not too much to ask can you please explain a bit about the code.
Thanks 
BALAJI CHBALAJI CH
Hi Nelum,

Good to listen that its working for you.
The code which you put in the question is perfect if the Button is on Quote Object. But when you said that Button is on Opportunity Object, we cannot directly use "{!Quote.Status}" to get the Quotes's Status value. So, we need to retrieve the Opportunity's related Quote record to get the value of Status in that Quote record.
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

//Below Line is to retrieve Data from Salesforce using sforce connection by passing a query ansd stores in result. In the query, we are getting Quote record of the Opportunity on which button is clicked.
var result= sforce.connection.query("select id, Status from Quote where opportunityid ='{!Opportunity.Id}'");

//This line gets the records into Array form from result and stors in records.
var records = result.getArray("records");

//Since we have only one quote record, we can use records[0] to get values of that record.
if(records[0].Status != "Approved")
{
alert("Quote needs to be approved ");
}

else{
window.open('/apex/echosign_dev1__AgreementTemplateProcess?masterid={!Opportunity.Id}&templateId=a0X2000000ARCFK');
}
Let us know if you have more questions.
Please mark a Best answer to close this thread so that it can be useful to others if required.

Best Regards,
BALAJI
This was selected as the best answer
Nelum FernandoNelum Fernando
Hi Balaji,

Verywell explained, I understand it now. I appreciate your help vey much. THANK YOU.