+ Start a Discussion

Custom Button to relate Record Types



I created custon button for quotes. I want that when a user clicks a button, the quote record type is determined by the opportunity record type (and the user don't have to pick the quote record type).

I know this can be solved somehow with condition in the URL, so I created something, but it didn't work:


/0Q0/e?retURL=%2F{!Opportunity.Id}&oppid={!Opportunity.Id} & if {{!Opportunity.RecordTypeId} = "012U00000004sGd", {!Quote.RecordType}= "012U000000053px", {!Quote.RecordType}= "012U000000053q2"}&ent=Quote








I'm not sure you can put logic in the middle of the URL.


Disclaimer: I don't really know Javascript, and maybe someone else has a better approach, but I think you could take a button that creates a new record and work in some if statements to get the right value for record type. Here is an example of a button that creates a new record and pulls in existing information from a related record. You would replace "MTT__c" with "Quote" (or whatever the API name is) and "Task_Order__c" with "Opportunity" and your fields, and you'd have to make sure to set the Opportunity ID and whatever else is required on Quote. 


{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js" )}
var connection = sforce.connection;
sforce.connection.login("yourusername", "yourpasswordsecuritytoken");
var a = new sforce.SObject("MTT__c"); 
a.Name = "{!Task_Order__c.Name}";
a.Start_Date__c=new Date("{!Task_Order__c.Start_Date__c}");
a.End_Date__c=new Date("{!Task_Order__c.End_Date__c}");
var result = sforce.connection.create([a]);


What you want to work in before the "var result" line would be an if statement for each Opportunity/Quote record type combination. I think you could find some examples of how to write an if statement in Javascript.


Then put the custom button on your Quotes related list on your Opportunity layout instead of the standard button.


Maybe someone else can refine this idea--again, just seems like it might work.