2_under_par
asked on
Auto populate Contract Template (lookup field) on FormLoad
When working with the Contract entity, the CONTRACT TEMPLATE field is required. Since we're not using that field, I'd like to have the form automatically populate it with "Service". (the only value available)
I tried the following 2 pieces of code and neither worked. Any Suggestions?
if (crmForm.all.contracttempl ateid.Sele ctedText == null)
{
crmForm.all.contracttempla teid.Selec tedText == "Service";
}
if (crmForm.all.contracttempl ateid.Data Value == null)
{
crmForm.all.contracttempla teid.DataV alue == "Service";
}
I tried the following 2 pieces of code and neither worked. Any Suggestions?
if (crmForm.all.contracttempl
{
crmForm.all.contracttempla
}
if (crmForm.all.contracttempl
{
crmForm.all.contracttempla
}
ASKER
"How are you creating a contract record without choosing the type first?" Good Question....
Within the Opportunity Entity, I created a 1:N Relationship between Opportunities & Contracts. Then, I linked some custom fields that we are using in both Entities. So, within an open Opportunity, you can click on the Linked Contract Menu on the left. When doing so, you may create a new Contract and all of the Mapped custom fields are Imported into the new Contract. This process bypasses the screen to select a Contract Template, but I can't autopopulate it.
I was able to get the GUID of the Contract Template by opening it up & doing a CTRL - N. I'm not good with Arrays, though... and that last line threw me a bit. Forgive me, but this is what I've got so far...
if (crmForm.all.contracttempl ateid.Sele ctedText == null)
{
var contractTemplate = new Array(new Object());
contractTemplate[0].id = "77ECDFDA-3E70-429D-B174-1 352B981C5F 2";
contractTemplate[0].name = "SER";
contractTemplate[0].type = 2011;
contractTemplate[0].typena me = "contracttemplate";
crmForm.all.contracttempla teid.AddIt ems(lookup CampaignID );
}
I'm assuming there's something obvious that I need to replace in the code above?
Within the Opportunity Entity, I created a 1:N Relationship between Opportunities & Contracts. Then, I linked some custom fields that we are using in both Entities. So, within an open Opportunity, you can click on the Linked Contract Menu on the left. When doing so, you may create a new Contract and all of the Mapped custom fields are Imported into the new Contract. This process bypasses the screen to select a Contract Template, but I can't autopopulate it.
I was able to get the GUID of the Contract Template by opening it up & doing a CTRL - N. I'm not good with Arrays, though... and that last line threw me a bit. Forgive me, but this is what I've got so far...
if (crmForm.all.contracttempl
{
var contractTemplate = new Array(new Object());
contractTemplate[0].id = "77ECDFDA-3E70-429D-B174-1
contractTemplate[0].name = "SER";
contractTemplate[0].type = 2011;
contractTemplate[0].typena
crmForm.all.contracttempla
}
I'm assuming there's something obvious that I need to replace in the code above?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Any luck getting this to work?
ASKER
Thanks jd_wright, that worked great! I had an issue with another line of code that kept this from working. After removing the bad code, this worked pefectly fine.
I did change SER to Service in my final code, but your code worked also. So, I'm giving you all the points.
if (crmForm.all.contracttempl ateid.Sele ctedText == null)
{
var contractTemplate = new Array(new Object());
contractTemplate[0].id = "77ECDFDA-3E70-429D-B174-1 352B981C5F 2";
contractTemplate[0].name = "Service";
contractTemplate[0].type = 2011;
contractTemplate[0].typena me = "ContractTemplate";
crmForm.all.contracttempla teid.AddIt ems(contra ctTemplate );
}
I did change SER to Service in my final code, but your code worked also. So, I'm giving you all the points.
if (crmForm.all.contracttempl
{
var contractTemplate = new Array(new Object());
contractTemplate[0].id = "77ECDFDA-3E70-429D-B174-1
contractTemplate[0].name = "Service";
contractTemplate[0].type = 2011;
contractTemplate[0].typena
crmForm.all.contracttempla
}
ASKER
Autopopulate Contract Template
The contract type is a related entity. Adding a value to a lookup field can be done with javascript like this:
var contractTemplate = new Array(new Object());
contractTemplate[0].id = "9E1B393B-AAD6-DD11-8632-0
contractTemplate[0].name = "SER";
contractTemplate[0].type = 2011;
contractTemplate[0].typena
crmForm.all.contracttempla
In order to use this, you'll have to get the guid for the "Service" contract template (if you open the template itself and then click F11, the value inside the {} in the page address is the GUID - "http://crm/tools/contracttypemanager/edit.aspx?id={54D8EE69-9B4F-4966-BB2C-