+ Start a Discussion
BtormarBtormar 

Override 'New' Opportunity button

I am trying to override the 'New' opportunity button as I'd like to pass some values when it is clicked (opportunity name = account name among others). The code below works - however, it's doing a 'double-load' when I click the new button. Does anyone know why it does that or how I can fix it? For instance, if I have several record types to choose from it will ask me twice which record type I want before it takes me to the new opportunity screen.
 
<html>
<head>
<script src="/soap/ajax/8.0/connection.js">
</script>
<script>
function new_URL()
{
window.parent.location.href ="{!URLFOR($Action.Opportunity.New,null,[accid=Account.Id,opp3= Account.Name ],TRUE)}";
}
</script>
</head>
<body onload="new_URL()">
<p>&nbsp;</p>
</body>
</html>
 
Thanks!
michaelforcemichaelforce
I would try changing the s-control to type = URL, instead of HTML and then cut it down to just the URLFOR statement.
MigMig
<script>
function new_URL()
{
parent.location.href ="{!URLFOR($Action.Opportunity.New,null,[accid=Account.Id,opp3= Account.Name ],TRUE)}";
}
</script>

Don't call the object Window !
just try to made it like this ...
Greg HGreg H
Try adding the parameter "nooverride=1" to your URLFOR function.  I know that this parameter stops the infinite reloading of the page when I pass my values directly in the URL.
-greg
BtormarBtormar

Thanks guys - all good suggestions, however, no luck unfortunately.

I even tried hard-coding the link, and still it does the 'double-load'...

Greg HGreg H
I wonder if the issue is with the URLFOR function you are using.  I don't believe that the override on the New button happens until after the recordtype is selected.  Since you are using the URLFOR function it is sending you back to the recordtype selection page with the parameters you are passing to the page.
 
Try using JavaScript instead of your URLFOR function and let me know how it works.  Here's a sample:
Code:
function new_URL() {
 var url = parent.location.href; //URL accessing sControl
 url += "&accid={!Account.Id}";
 url += "&opp3= {!Account.Name}";
 url += "&nooverride=1"; //pass nooverride parameter to prevent infinite reloading of new opp page
 parent.location.href = url; //pass full URL to page (refresh)
}

Don't get me wrong, there will still be a delay in the response time between pages due to the fact that it is an sControl but you should bypass that second selection of recordtype.
-greg
Vijay RautVijay Raut
Hi All,

I am also having same problem in overriding one of my custom object new button (Which uses the Record Type).

Does any one from community has got any workarround? id so then please reply to this thread.

Thanks
V. R.
BtormarBtormar
You're right Greg - that did it, it removed the second selection of a record type.
 
Thanks!
taPhiltaPhil

We had the need for this too, but from the Opportunity related list on the Account detail page.  The following URL on a custom button on the Opportunity worked fine.  Don't know if this helps.  We would never want to create and opportunity from the Opportunity Home page/tab, just from Accounts, so this approach might not help all.

 

/006/e?retURL=%2F{!Account.Id}&accid={!Account.Id}&opp3={!Account.Name}

 

The standard button for this list is "New Opportunity".  I've replaced this with our own "New Opportunity" button, as described above.

Keith987Keith987

I came across this post when working on a related problem. Here is a link to what I ended up with:

 

Automatically setting the record type of a detail object based on the record type of its master object

 

Keith