You need to sign in to do that
Don't have an account?
Adriana Voyce
JS button to update Opportunity "Unexpected Token Illegal"
I am trying to create a button that will update the stage of an opportunity to a specific stage, and the owner to whom ever clicks the button, additionally I want the update to happen only if a specific profile clicks the button (this may be best accomplished through a validation rule though so its not in my code)
This is what I have written just trying to get the stage to change.... I get this error: "Unexpected Token Illegal"
***Note*** I am not a developer but trying to learn so my knoweledge is mimited
{!requireScript("/soap/ajax/10.0/connection.js")};
sforce.connection.session = "{!$Api.Session_ID}";
function updateOpportunity( )
{
try
{
var opp = new sforce.SObject(“Opportunity”);
opp.id =”{!Opportunity.Id}”;
opp.StageName = "AE Qualified”;
var saveResult = sforce.connection.update([Opportunity]);
if (result[0].getBoolean("success") == false ) {
alert(result[0].errors.message);
return;
}
window.top.location.href=window.top.location.href;
}
catch (e) {
alert(e);
}
}
updateOpportunity();
This is what I have written just trying to get the stage to change.... I get this error: "Unexpected Token Illegal"
***Note*** I am not a developer but trying to learn so my knoweledge is mimited
{!requireScript("/soap/ajax/10.0/connection.js")};
sforce.connection.session = "{!$Api.Session_ID}";
function updateOpportunity( )
{
try
{
var opp = new sforce.SObject(“Opportunity”);
opp.id =”{!Opportunity.Id}”;
opp.StageName = "AE Qualified”;
var saveResult = sforce.connection.update([Opportunity]);
if (result[0].getBoolean("success") == false ) {
alert(result[0].errors.message);
return;
}
window.top.location.href=window.top.location.href;
}
catch (e) {
alert(e);
}
}
updateOpportunity();
Yes your code was very close. I have enhanced the code to change the owner to user that clicked the button but only if the users role contains AE or is an Admin. I tested code works fine.
Please remember to mark this as a solution/answer if this resolves your question.
All Answers
If you want to validate the profile name in the code its self, you can do it like this:
Hope it helps.,
Thanks,
balaji
I was able to reproduce the error and fix it.
You code (updated) below works now.
Yes your code was very close. I have enhanced the code to change the owner to user that clicked the button but only if the users role contains AE or is an Admin. I tested code works fine.
Please remember to mark this as a solution/answer if this resolves your question.
As I understand there is existing logic in system which does not allow AE's to change the owner for opportunities to themselves currently(lets call it A ). I think we need to do some change there(in A ) too to make it happen. Why dont we takeoff A's logic for AE and put that whole logic in JS.
That way it is possible. If you explain me how permissions are enforce for A then I can try to find s solution.
Thanks
Amit