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
morgan130morgan130 

Help with S-Control to copy Opportunity Fields to Contract based on Contract Record Type

I need help pointing me to the documentation that describes how to create an s-control for the following:
 
Background:
- We have created a lookup field from the Contract to the Opportunity since all of our Contracts are associated with an Opportunity
- We are using Contract Types to distinguish the differences in required fields based on type, and have associated page layouts for each type. 
- Some Contract Types are direct results of an Opportunity (Acquisition, Renewal), while other Contracts are actually addendums or changes to the original Contract.  These Contracts will supersede the original Contract.  (These are the cases where we may have more than one Contract associated with an Opportunity.)
 
Solution Needed:
- We would like to override the "New" button for the Contract detail list within the Opportunity page so that for specific Contract Record Types (Acquisition, Renewal but not Addendums), 5 fields from the Opportunity will be copied to the Contract.
 
We started with a trigger that populates the Contract fields from the Opportunity fields, but of course, this happens after the user selects to save the new Contract.  We would like the fields to be prepopulated on the Contract detail page before the user starts entering fields for the Contract.
 
Any help you can provide would be most appreciated!
RexRex
You can URL Rewritting concepts for this. Have you done anything on this before?
morgan130morgan130

Apologies, Rex.  I didn't understand what you meant by "URL rewriting concepts". 

No, I have not done anything like this before.  I have read a lot of posts that have examples that are close, and there is a ton of documentation, I'm just missing the documentation that gives an overview of the syntax for doing this.  I know generally about custom links and using URLFOR...

RexRex
BTW. How much do you know about Visual Force. Visual Force is the right way to go to get this done because from what i understand you need a custom code sitting between the page where you select the record type and the next page. But if you are not sure you could go the VF route then if you can answer my question:
 
Is it fine if you have 3 buttons (one for each Record Type) i.e. there will be 3 or more buttons depending on how many Record Types you have. These buttons will be on the related list of Contracts?
morgan130morgan130

Hey Rex,

We have not explored Visualforce pages...although I understand that s-controls have a short life, and visualforce pages look like they are incredibly powerful.  We have some limitations with our technical resource expertise, so for our initial launch, we have approved using s-controls (and Apex).

I appreciate your response as it has confirmed that we might pick a short term solution of adding a custom button to the Contract page that allows the user to select it to "refresh" those fields from the Opportunity at will.  While this is not an optimal user experience and will cost the user an additional step of creating the object and then selecting the button, at least the user has total knowledge of when the fields get updated.  (We had also discussed adding triggers for Opportunity add/update to keep the fields in sync and then protecting those fields on the Contract but there are some cases where we might need to vary from that syncing rule.)

The buttons you suggest are a great idea...although we actually have 9 record types total, so that may be a bit much for our particular scenario.  But I do appreciate your help and quick response.  This was my first experience using the discussion boards...and you've made that a good experience!

RexRex
you've made that a good experience! -  Thank you for that. Yes i am just returning a favour. These Boards helped me when i started with SF so i just help when i get time out of my work. So a immediate fix for your issue.
 
>Call an s-contorl on the new page for now lets call it custom contract page.
>The page should have a picklist of all the Record Types in the system for now hard code it (Lets take one step at a time :-)). Each Record Type in SF has Id's associated with it. You can find them in the URL when you go to setup and view the Record Type.
>Throw in 2 buttons continue and cancel. Continue will take the user to next page and cancel to go back.
> If the user selects Renewal and clicks continue then change the URL of the page to the following
 
https://na3.salesforce.com/800/e?&RecordType=(RTID)
 
some interpretation of the above URL
 "na3.salesforce.com" - this is the server which should be different for you.
 800 - the represents the object to SF 800 means contract which should be the same for you.
RTID - this where you have to put in the record type id. this way u are telling SF which page it should show.
 
>Now to prepopulae the fields: if you didnt now SF always send information from its previous page to the s-control thourgh merge fields. So you can get all the field values of the opportunity that you called from using this. eg.
 
{!Opportunity.Name} gives you the opp name of the record from which you called from. In your s-control you can write,
 
var oppName = {!Opportunity.Name};
 
store it in variables for all the fields that you need from opportunity.
 
>Finally prepopulating them in Contracts New Page.
Now append the required variables to the end of the URL. Lets assume you want to populate a field called Contract Opp Name which is a custom field. First you have to find the id of the field the only way to find that is to go to a contract record and edit it. Then right click and look at the source code. Search for the field name which is "Contract Opp Name" you should see something like this.
 
<label for="00N50000001MD9O">Contract Opp Name</label>
 
text after the for is the ID now send that through the URL. Now your URL should look something like this
 
var contractURL = "https://na3.salesforce.com/800/e?&RecordType=(RTID)&00N50000001MD9O=" + oppName
 
you can add as much fields you need.
 
Hope this is clear i know its long probably i could have done this for you in this time but :-) always better to learn. Let me know if you have any questions. Alright


Message Edited by Rex on 08-28-2008 12:24 PM

Message Edited by Rex on 08-28-2008 12:25 PM