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
David GunnDavid Gunn 

Change custom "New Quote" URL button to javascript button

In our instance we have a custom quote button (URL button) that only contains this code:

/apex/NewQuoteRedirect?retURL=%2F{!Opportunity.Id}&oppid={!Opportunity.Id}

I would like to change this to an OnClick Javascript button to which I can add some validation code (to make sure a new Opportunity Product custom field is populated in each of the opportunity's products)

How can I convert the above line to Javascript?
Best Answer chosen by David Gunn
David GunnDavid Gunn
Vatsal and Karanraj: I had already changed the button to a OnClick Javascript, but was unable to do a redirect successfully. I had tried the window.location but it didn't do anything.

Thanks to the link Karanraj gave me I found the code in that page used parent.window.location, so I used that and it now works:

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

// Do some validation here

parent.window.location = '/apex/NewQuoteRedirect?retURL=%2F{!Opportunity.Id}&oppid={!Opportunity.Id}';

Thanks to both of you for your quick replies.

All Answers

KaranrajKaranraj
David - Change the content source of your button into onClick Java script  and check this link for sample code to use java script in the custom button https://developer.salesforce.com/page/The_Contention-Proof_Case_Accept_Button
Vatsal KothariVatsal Kothari
Hi,

You can create javascript button using below code :

window.location = 'apex/test?retURL=%2F{!Opportunity.Id}&oppid={!Opportunity.Id}'

If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal
David GunnDavid Gunn
Vatsal and Karanraj: I had already changed the button to a OnClick Javascript, but was unable to do a redirect successfully. I had tried the window.location but it didn't do anything.

Thanks to the link Karanraj gave me I found the code in that page used parent.window.location, so I used that and it now works:

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

// Do some validation here

parent.window.location = '/apex/NewQuoteRedirect?retURL=%2F{!Opportunity.Id}&oppid={!Opportunity.Id}';

Thanks to both of you for your quick replies.
This was selected as the best answer