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
Den1Den1 

Override New button on Case when user has multiple record types

We have an s-control to override the New button on the Case to pass in some default values from the user record.
It works fine, unless...
 
the user has multiple record types and they do not want to select the default record type.
 
ie. user is presented with the select record type page on clicking New
Selects a record type that is NOT the default one
The default loads anyway
 
The url shows 2 record type ids, first the selected one and then the default one. The default takes precedence.
 
 
The field to be updated and values are on both record types.
 
Any ideas?
Best Answer chosen by Admin (Salesforce Developers) 
NaishadhNaishadh

Hope following code will help u for that.

 

 <html>
<head>
<script>
var userSegment = escape("{!User.Segment__c}");


function new_URL()
{
var url = parent.location.href; //URL accessing sControl

var completeUrl = url + '&00N40000001V3eF='+userSegment;

completeUrl += "&nooverride=1"; //pass nooverride parameter to prevent infinite reloading of new opp page

parent.location.href = completeUrl; //pass full URL to page (refresh)
}
</script>
</head>
<body onload="new_URL()">
</body>
</html>

Message Edited by Naishadh on 02-01-2009 11:05 PM

All Answers

TCAdminTCAdmin
Hello Den1,

To pass information through the record type selection you would need to use the following base for the formula. Your field values will need to be placed after the save_new_url value. By using the link below it will take your users to the Opportunity's record type selection page.

Code:
/setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=/006/e?opp4={!Account.Name}

 

NaishadhNaishadh
Is it means we need to write
 
newUrl = '/setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=/006/e';
 
in place of
 
newUrl = '{!URLFOR($Action.Opportunity.New, null, null, true)}'
 
werewolfwerewolf
Of course in your situation you'd want to replace any references to Opportunity with references to Case, and any references to 006 (the key prefix for opportunites) with references to 500 (the key prefix for cases) instead.
NaishadhNaishadh
<script>

var userRegion = escape("{!User.User_Region__c}");


newUrl = '/setup/ui/recordtypeselect.jsp?ent=Case&retURL=%2F500%2Fo&save_new_url=%2F500%2Fe';

var completeUrl = newUrl +  '?retURL=%2F500%2Fo&cancelURL=%2F500%2Fo&ent=Case&00N30000000crel='+userRegion;

window.parent.location.href = completeUrl;

</script>

Above S-control code work fine for custom new button but for default new button, I stuck with infinite loop on recordType select page.

Any Idea?
TCAdminTCAdmin
I think on the standard button you will want to add &nooverride=1. This will make sure it utilizes the standard functionality instead of the custom features you have added.
werewolfwerewolf
Right, or just stick with the custom button and hide the standard new button.
NaishadhNaishadh
with &nooverride=1 it stop infinite loop but still recordtype page appear two time. i.e. click on case new button, it open recordType page, after selecting recordType when I click on continue it again show same recordType page. After reselecting recordType, when I heat continue it redirect to Case creationg page.

Do I need to add any more parameter? Please guide


werewolfwerewolf
Like I said, don't override the New button, just make a custom button that does what you want that is also labeled "New" and use that instead.
Den1Den1
But that won't work if they use the "Create New..." drop down in the left pane  - it will return the default sfdc behaviour
Den1Den1
We are very close to solving this issue but are stuck on the following.
 
Hit Create Case
Select Record Type - if default type NOT selected - opens default type anyway (ie. ignores selection)
Hit Create Case again
Select Record Type - if default type NOT selected - opens selected record type
 
 
So we seem to be in some sort of loop...which runs once
 
We tried with &nooverride=1 and had the same results.
 
This is the current code:
 
var newUrl = '{!URLFOR( $Action.Case.NewCase , null, null, true)}';
var completeUrl =newUrl+'&00N30000000bbb='+userRegion;

if ("{!$Request.def_contact_id}" != "")
completeUrl += '&def_contact_id={!$Request.def_contact_id}';

if ("{!$Request.def_account_id}" != "")
completeUrl += '&def_account_id={!$Request.def_account_id}';

if ("{!$Request.def_asset_id}" != "")
completeUrl += '&def_asset_id={!$Request.def_asset_id}';

if ("{!$Request.cancelURL}" != "")
completeUrl += '&cancelURL={!$Request.cancelURL}';


var saveX = "";
if ("{!$Request.RecordType}" != "") // there is a record type param in URL
saveX = "&save=x";

if ("{!$Request.cancelURL}" != "") {
completeUrl += '&cancelURL={!$Request.cancelURL}';
} else {

completeUrl += '&cancelURL=/500/o';
}

// put together the final URL
completeUrl += saveX;

window.parent.location.href = completeUrl;
 
 
 
werewolfwerewolf
That's because you're eating the record type URL setting.  Notice that versus the standard New record link, your URL is going to be lacking the &RecordType=01230000000DTc9 (or whatever record type is that you choose) because when the RecordType param is present you are for some reason appending a &save param instead:

if ("{!$Request.RecordType}" != "") // there is a record type param in URL
saveX = "&save=x";


NaishadhNaishadh

Following is more generalize code

<script>

var completeUrl = '{!URLFOR( $Action.Case.NewCase , null, null, true)}';

completeUrl += '&cancelURL={!$Request.cancelURL}&RecordType={!$Request.RecordType}';

window.parent.location.href = completeUrl;
</script>

Still it display recordType section page twice. any idea?

micwamicwa
any solution? I have the same problem.
NaishadhNaishadh

Hope following code will help u for that.

 

 <html>
<head>
<script>
var userSegment = escape("{!User.Segment__c}");


function new_URL()
{
var url = parent.location.href; //URL accessing sControl

var completeUrl = url + '&00N40000001V3eF='+userSegment;

completeUrl += "&nooverride=1"; //pass nooverride parameter to prevent infinite reloading of new opp page

parent.location.href = completeUrl; //pass full URL to page (refresh)
}
</script>
</head>
<body onload="new_URL()">
</body>
</html>

Message Edited by Naishadh on 02-01-2009 11:05 PM
This was selected as the best answer
micwamicwa

What excactly is the "Segment__c" field on the User object?

 

What I need is creating a new product (product has multiple recordtypes) where the name has already a standard value. The user should be able to choose the recordtype as usual.

 

With this url the recordtype must be chosen twice:

 

window.parent.location.href = "{!URLFOR($Action.Product2.Add, null, [Name = 'my default value', retURL = '/%2Fhome%2Fhome.jsp'], true)}";

 

 

 

NaishadhNaishadh

Segment__C is my custom field. It's just for example. In your case it's name field.

 

try to override field value in form load event as shown in my previous scrap.

 

 

micwamicwa
It works now, thanks for your help.
DcoderDcoder

Hi,

 

 

 

What if we need to show the selected recordtype's value in a custom text box on the same field?

 

 

werewolfwerewolf
Why would you want to show the selected recordtype's value in a custom text box on the same field?  The record type will already be shown in the Record Type field.  It's just not editable.
DcoderDcoder

yes :) , I understand that it is shown on the page but users want to have that populated as part of the custom text box. I have used the sample code shown on this thread and I am able to show the values for account object on the related custom objects (having multiple recordtypes) successfully through the URL way. But  now I want to have the recordtype value populated too. Please guide me.

 

Thanks

Dcoder

NaishadhNaishadh
Try this

Pagereference newPage = new Pagereference(pageurl); newPage.getParameters().put(IPropertyNames.NO_OVERRIDE, IPropertyNames.ONE); newPage.getParameters().put(IPropertyNames.RETURN_URL,ApexPages.currentPage().getParameters().get(IPropertyNames.RETURN_URL)); newPage.getParameters().put(IPropertyNames.CONFIRMATION_TOKEN,ApexPages.currentPage().getParameters().get(IPropertyNames.CONFIRMATION_TOKEN)); newPage.getParameters().put(IPropertyNames.CANCEL_URL,ApexPages.currentPage().getParameters().get(IPropertyNames.CANCEL_URL)); newPage.getParameters().put(IPropertyNames.ENT,ApexPages.currentPage().getParameters().get(IPropertyNames.ENT)); String recordType = ApexPages.currentPage().getParameters().get(IPropertyNames.RECORDTYPE); if(recordType != null) { newPage.getParameters().put(IPropertyNames.RECORDTYPE,recordType); }return newPage;

 

Collen Mayer 6Collen Mayer 6
Don't know if anyone is still following this thread, but I have a similar problem.  I'm sure the existing solution would work, but could use some help with the code.  My thread is here: 

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000kAtSIAU 

Thanks!