CRM 4.0 Concatenate Lookup Fields or regular fields on Form

Found a couple of solutions posted in the MS forums on this post, I had the best luck with the following:

To start update new_OpportunityID and new_ContactID with your fields, this example concatenates the Opportunity ID and Contact ID lookup fields.

var lookupItemOppID = new Array;
lookupItemOppID = crmForm.all.new_OpportunityID.DataValue;

var vOpportunityID= (lookupItemOppID[0] != null) ? lookupItemOppID[0].name : "";

var lookupItemConID = new Array;
lookupItemConID = crmForm.all.new_ContactID.DataValue;

var vContactID= (lookupItemConID[0] != null) ? lookupItemConID[0].name : "";

CrmForm.all.new_name.DataValue = vOpportunityID + " - " + vContactID;

This will concatenate two normal fields

crmForm.new_fullname.DataValue = crmForm.new_firstname.DataValue + " " + crmForm.new_lastname.DataValue;

This will concatenate a lookup field and a normal text field

if(crmForm.all.new_abreviationid.DataValue!=null)

var nameval=crmForm.all.new_abreviationid.DataValue[0].name;

crmForm.all.new_uasi.DataValue=nameval+","+crmForm.all.new_name.DataValue;

Then once you have the field completed you will want to force the change to the database. This will be necessary when a user changes one of the values that creates the concatentated field. It will show the change on the form, however it will not force the change to the database.

//force the result to the database
crmForm.all.DesiredField.ForceSubmit = true

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>