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
boBNunnyboBNunny 

Override of New button

Hi all.  I've been able to override Edit and Delete buttons.  But when I override the New button (on a child object), I just get a blank i-Frame, but no errors as shown on the status bar with an exclamation point.  I've attached the "View Source" from the i-Frame.  It seems it sees the script, but just doesn't want to execute it.  Any ideas?
 
Code:
<script  type="text/javascript">function getRecordIds(keyPrefix) { return [] }</script>
<script  type="text/javascript">this.__sfdcSessionId = 'URg3C3XdgX6J6zgBrjXUW9dKBYWdvmYiuDA1IIbxSiYw8wdSoYUAe9XIY4n4389T.Ps8ktT1SsV3Fh3TalS5iFtm0eZXn.oO3HqtZiMtDQ_9WR0F2VSOzr1Vmttbk__IheJaNwCU'</script>
<script type="text/javascript">
alert("I'm starting");
if("Approved" == "Approved" && "Product Pricing Exception" == "Product Pricing Exception")
{
//go to the standard detail page
alert("Sorry, once a Sales Exception is in Approved status, New is not authorized.");
window.parent.location.href = "/a0860000002BlLN/d";
}
else
{
//go to the standard new page
alert("New!");
window.parent.location.href = "/setup/ui/recordtypeselect.jsp—ent=01I600000009SXk&retURL=%2Fa0860000002BlLN%2Fd&save_new_url=%2Fa08%2Fe%3FretURL%3D%252Fservlet%252Fservlet.Integration%253Flid%253D01NT00000004Ig1%2526eid%253Da0O%2526ic%253D1%2526CF00NT0000000ijhA%253DPreferred%252BPlus%252BDiscount%2526CF00NT0000000ijhA_lkid%253Da0860000002BlLN%2526scontrolCaching%253D1%2526retURL%253D%25252Fa0860000002BlLN%2526RecordType%253D012T00000004KRI%2526cancelURL%253D%25252Fa0860000002BlLN%2526ent%253D01IT0000000Cjpa%2526save_new%253D1%2526autoMapValues%253D1&nooverride=1";
}

 
boBNunnyboBNunny

I was able to get the code to work (I was missing an ending </script>).

However, another problem arises with the "New" record asking for RecordType before it hits the script, then after the script fires and calls the New screen, it asks for the RecordType again.

Does anyone have any idea how to bypass this behavior?

KringoKringo
I would be interested to know. The only was I have found to do it with my limited coding experience is to set the recordtype in the code that fires on the custom button. So I have 3 "new" buttons and each one creates a new record of a specific record type.

It wasn't what I wanted but does have the advantage of eliminating a step.
ckempckemp
To override the New button in order to set up some custom logic that happens beforehand, set up an S-control that looks something like this:

Code:
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/11.0/connection.js"></script>
<script src="/soap/ajax/11.0/apex.js"></script>
<script type="text/javascript">
    // Do pre-processing stuff here...

    // Redirects to the real "New" page by overriding the override :-)
    this.parent.location.href = "{!URLFOR($Action.YourObjectName__c.New, null, null, TRUE)}";
</script>

 If you don't include that last TRUE bit, then you'll just redirect back to this script in an infinite loop.