We help IT Professionals succeed at work.

Auto populate Contract Template (lookup field) on FormLoad

2_under_par
2_under_par asked
on
1,752 Views
Last Modified: 2012-08-13
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.contracttemplateid.SelectedText == null)
    {
     crmForm.all.contracttemplateid.SelectedText == "Service";
    }

if (crmForm.all.contracttemplateid.DataValue == null)
    {
     crmForm.all.contracttemplateid.DataValue == "Service";
    }
Comment
Watch Question

Jeff WightBusiness Solutions Manager

Commented:
How are you creating a contract record without choosing the type first?  I thought that was a mandatory part of creating a contract.  Was data imported into this entity?


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-005056867069";
      contractTemplate[0].name = "SER";
      contractTemplate[0].type = 2011;
      contractTemplate[0].typename = "contracttemplate";
                                    
crmForm.all.contracttemplateid.AddItems(lookupCampaignID);

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-581E3453DDE7}" has a guid of 54D8EE69-9B4F-4966-BB2C-581E3453DDE7).  Put this value, minus the brackets, into the snippet above and it should put the Service contract value into the ContractId field.  You'll still want to check and see if there is a value there already first.

Author

Commented:
"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.contracttemplateid.SelectedText == null)
    {
     var contractTemplate = new Array(new Object());
      contractTemplate[0].id = "77ECDFDA-3E70-429D-B174-1352B981C5F2";
      contractTemplate[0].name = "SER";
      contractTemplate[0].type = 2011;
      contractTemplate[0].typename = "contracttemplate";
                                   
      crmForm.all.contracttemplateid.AddItems(lookupCampaignID);
    }

I'm assuming there's something obvious that I need to replace in the code above?
Business Solutions Manager
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Jeff WightBusiness Solutions Manager

Commented:
Any luck getting this to work?

Author

Commented:
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.contracttemplateid.SelectedText == null)
    {
     var contractTemplate = new Array(new Object());
      contractTemplate[0].id = "77ECDFDA-3E70-429D-B174-1352B981C5F2";
      contractTemplate[0].name = "Service";
      contractTemplate[0].type = 2011;
      contractTemplate[0].typename = "ContractTemplate";
                                   
      crmForm.all.contracttemplateid.AddItems(contractTemplate);
    }

Author

Commented:
Autopopulate Contract Template

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.