Question Status

Suggested Answer
ramu1000 asked a question on 16 Jul 2013 2:19 PM

I am creating a custom web application capturing contact information(using ASP.net and C#), then updating the information into CRM on- Premise. And I am able to Update all the information into CRM 2011 Successfully expect Lookup Attribute value So could you please let me know if suppose custom entity contains lookup field how will map them into MS CRM 2011?

Reply
Andrew Campey responded on 16 Jul 2013 5:43 PM

You need an entity reference

Microsoft.Xrm.Sdk.AttributeCollection attributeList = new Microsoft.Xrm.Sdk.AttributeCollection();

EntityReference fieldreference = new EntityReference();
fieldreference.Id = TheIDOfTheLookupRecordGoesHere;
fieldreference.LogicalName = TheNameOfTheLookupEntityGoesHere;
attributeList.Add(TheNameOfTheLookupFieldGoesHere, fieldreference);

For Example:
Microsoft.Xrm.Sdk.AttributeCollection attributeList = new Microsoft.Xrm.Sdk.AttributeCollection();

EntityReference fieldreference = new EntityReference();
fieldreference.Id = new Guid("E3B6702F-3EE5-E211-BF68-1CC1DEEB47C0");
fieldreference.LogicalName = "Contact";
attributeList.Add("ContactLookup", fieldreference);

Reply
Suggested Answer
Scott Durow responded on 17 Jul 2013 12:41 AM

Provided that you have the Guid and the logical entity name of the record you want to associate with the custom entity via the lookup - you simply need to use an EntityReference:

target["attributename"] = new EntityReference("account", myAccountId);

Scott Durow

Read my Blog   |  Follow Me on Twitter  |  Rockstar365

Reply
Scott Durow responded on 12 Aug 2013 7:24 AM

Hi,

How did you get on with this? Did you get it working?

Cheers!

Scott Durow

Read my Blog   |  Follow Me on Twitter  |  Rockstar365

Reply
Suggested Answer
Scott Durow responded on 17 Jul 2013 12:41 AM

Provided that you have the Guid and the logical entity name of the record you want to associate with the custom entity via the lookup - you simply need to use an EntityReference:

target["attributename"] = new EntityReference("account", myAccountId);

Scott Durow

Read my Blog   |  Follow Me on Twitter  |  Rockstar365

Reply