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

Plugin error on update entity field

$
0
0

Trying to update incident entity Description field on Case update. And got:

On Case create the same construction works fine. What's wrong?

namespace MyPluginPackage.Plugin
{
    using System;
    using System.ServiceModel;
    using Microsoft.Xrm.Sdk;

    public class PostCaseUpdate: Plugin
    {

        public PostCaseUpdate()
            : base(typeof(PostCaseUpdate))
        {
            base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "incident", new Action<LocalPluginContext>(ExecutePostCaseUpdate)));
        }

        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)
            {
                Entity entity = (Entity)context.InputParameters["Target"];
                try
                {
                    entity["title"] = "Any Text";
                    service.Update(entity);
                }
                catch (FaultException ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
                }
            }
        }
    }
}

Thanks!


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


Viewing all articles
Browse latest Browse all 1000

Trending Articles