Quantcast
Channel: Microsoft Dynamics CRM
Viewing all articles
Browse latest Browse all 154803

Forum Post: RE: associate one to many relationship through code

$
0
0
Hi, A one to many relationship is basically a lookup. You have to set the value of the lookup. This can be done from either JavaScript or plugin code. The target record in both cases must exist. In JavaScript (one of the ways), you can call the following function, and pass the parameters as required: // fieldname: the attribute that you want to set // lookupid: the unique identifier of the relationship // lookupname: the text of the identifier // entityname: the logical name of the entity function setLookupField(fieldName, lookupId, lookupName, entityName) { var lookupData = new Array(); var lookupItem = new Object(); lookupItem.id = lookupId; lookupItem.name = lookupName; lookupItem.entityType = entityName; lookupData[0] = lookupItem; Xrm.Page.getAttribute(fieldName).setValue(lookupData); } In C#/Plugin code entity[lookupFieldName] = new EntityReference(id_of_lookup, targetEntityName); Hope this helps.

Viewing all articles
Browse latest Browse all 154803

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>