You need to sign in to do that
Don't have an account?
hassab
Custom button external url with formula
hello all,
I am trying to create a custom button on a standard page that redirects to one or the other external url based on a value in the record. So far I have not been able to get sf to do this - and if statement in javascript keeps giving me errors (don't know javascript that well so that could be my fault). Any ideas?
-Hassab
Hi Hassab,
You cannot use ISPICKVAL in javascript it is vf page functions. You have to refer the direct field in javascript like below
if('{!Contract.Record_Status__c}' == "Ready"){
MergeUrl = generateContractURL;
}
hope this helps.
All Answers
Hi Hassab,
Please post your javascript code so that we can be more helpful.
In the custom button, you can provide any external url. For example you can put http://www.google.com at the time to creating custom button so that the url will open on the click of the detail page button.
Hope this helps.
Hi, sorry, you can indeed put in any url you like but you can't do a formula with it unless you're using javascript. At least I couldn't get it to work.
what I am trying to do is do an if then else statement where the then and else point to two separate external urls and the condition is a value on the record. The external urls also need to pull values from the record and every time I try to even just build a variable to house the external urls as soon as I try to add a value to the string I can save it fine but when I go to run the button, even without any other code, I get "expected ';' "
Here's just trying to build the variable:
var viewContractUrl = "https://www.appextremes.com/apps/Conga/PointMerge.aspx?SessionId="
this works fine. it obviously doesn't do anything but it doesn't throw an error.
var viewContractUrl = "https://www.appextremes.com/apps/Conga/PointMerge.aspx?SessionId="+{!$Api.Session_ID};
this gives me the error "expected ';' "
so I guess my first question is, how do I build the url string? or is there an easier way to do this?
thanks,
H
OK, I was able to get the URL to be stored in a variable, but I'm still having trouble with the if statement. Here's my code:
var viewContractURL = 'https://www.appextremes.com/apps/Conga/PointMerge.aspx?SessionId={!API.Session_ID}&ServerUrl={!$Api.Partner_Server_URL_80}&Id={!Contract.Id}';
var generateContractURL = 'https://www.appextremes.com/apps/Conga/PointMerge.aspx?SessionId={!API.Session_ID}&ServerUrl={!$Api.Partner_Server_URL_80}&Id={!Contract.Id}';
var MergeUrl;
IF(ISPICKVAL(Contract.Record_Status__c, 'Ready')) {MergeUrl = generateContractURL;}
window.open(MergeURL);
If I take out the if statement and put in one of the variables all is well so it is definitely the if statement. Anyone know how to do an if in a sf javascript button?
Thanks,
Hassab
Hi Hassab,
You cannot use ISPICKVAL in javascript it is vf page functions. You have to refer the direct field in javascript like below
if('{!Contract.Record_Status__c}' == "Ready"){
MergeUrl = generateContractURL;
}
hope this helps.
That did it perfect!
Thanks so much Sarge!
Ooops, spoke too soon.
I was able to run the script via the button but that was only when the window open was pointing to one of the the predefined variables (I was just testing to see that it worked). When I point the window.open using the variable that is set via the if statement I get "mergeurl is undefined". here' s the code:
var viewContractURL = 'https://www.appextremes.com/apps/Conga/PointMerge.aspx?SessionId={!API.Session_ID}&ServerUrl={!$Api.Partner_Server_URL_80}&Id={!Contract.Id}&TemplateGroup=MediaAgreementViewOnly';
var generateContractURL = 'https://www.appextremes.com/apps/Conga/PointMerge.aspx?SessionId={!API.Session_ID}&ServerUrl={!$Api.Partner_Server_URL_80}&Id={!Contract.Id}&TemplateGroup=MediaAgreement';
var MergeUrl;
if('{!Contract.Record_Status__c}' == "Ready")
{MergeUrl = generateContractURL;}
else
{MergeUrl = viewContractURL;}
window.open(MergeURL);
nevermind - case sensitive variables <sigh>
thanks again Sarge!
Hi hassab,
Thanks for marking it solved. I suggest you to use Mozilla Firefox for debugging javascript. On any js execution, press Ctrl+Shift+j, which openes error console. It is very handy and points to right place in case of any js related errors/exceptions.