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
Scott.MScott.M 

URLFOR

Hi I'm attempting to write a custom button that generates a contract from an opportunity. It's working except I had to use a hack for the redirect after the contract is generated. Here's the code:

Code:
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

var opportunity_id = '{!Opportunity.Id}';

var result = sforce.apex.execute("CreateContract","createContractService", {opp_id : opportunity_id});

var newURL = 'https://tapp0.salesforce.com/'+result+'/e—retURL=%2F'+result; //HACK
window.parent.location.replace(newURL);

I'd like to replace the new url with:

Code:
var newURL = "{!URLFOR($Action.Contract.Edit, [result], null, false)}";
Where [result] is the id of the contract that was just created by the web service (the return value). Unfortunately these functions don't seem to have access to the javascript variables. Any ideas how I could pass the contract id to the URLFOR function. Keep in mind I'm in the opportunity detail context.

Thanks in advance for any help
 


SteveBowerSteveBower
Couldn't you use the code you want to use to create newURL but, instead of [result] use an unlikely string "XXXXXX".  Then, after you have the result, just use string substitution yourself to hack newURL into shape, substituting "result" for "XXXXXX".

Since the {!URLFOR... stuff is processed when the page is first loaded you can't refer to javascript variables.

Also note that although using URLFOR is probably the right way to go, you could also get rid of the
https://tapp0.salesforce.com/

by making newURL a relative url that looks like:

var newURL = "/" + result + "/e?retURL=/" + result;

Still a hack but less egregious.

Best, Steve.

sanjayrs23sanjayrs23

Thanks Steve, it helped.