Quantcast
Channel: Forum CRM Development
Viewing all articles
Browse latest Browse all 1000

CRM 2013. Could not get lookup

$
0
0

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.


Если сообщение оказалось полезным, пожалуйста, проголосуйте за него или пометьте в качестве ответа.


Viewing all articles
Browse latest Browse all 1000

Trending Articles



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