Trying to retrieve lookup field id or value, but always get an error
Here is the code:
protected void ExecutePostCaseUpdate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService; if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && context.Depth < 2) { Entity entity = (Entity)context.InputParameters["Target"]; try { if (entity.Attributes.Contains("customerid") == false) { var getLookup = (EntityReference)entity.Attributes["customerid"]; var getId = getLookup.Id; //.ToString() does not help too entity["description"] = getId; } service.Update(entity); } catch (FaultException ex) { throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex); } } }
Thanks for suggestions.
Если сообщение оказалось полезным, пожалуйста, проголосуйте за него или пометьте в качестве ответа.