Sunday, 10 November 2013

Set a lookup field on another form to null using oData using subgrid

When you a have a N:1 subgrid on a form you cannot simply remove the record as CRM only shows a delete button ('x'). Instead, add a subgrid button to the entity referenced in the subgrid that will run a script that uses oData and jSon to set the referenced lookup to null. How you do this is to set the object reference of the lookup field to null as follows; CRMObject.= {Id: null , LogicalName: null, Name: null}; Ensure all three Id, LogicalName, and Name are set to null otherwise it won't work per Microsoft's SDK reference below... In order to set Microsoft CRM Complex Types to null, you must explicitly set each primitive type within them to null. For example, to set an EntityReference type to null, you must set the Id, the LogicalName, and the Name properties to null. The same is true for OptionSetValue, Money, and BooleanManagedProperty.

No comments:

Post a Comment