web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

CRM Plugin Did not Update All Fields

(0) ShareShare
ReportReport
Posted on by 25

We're on CRM 2016 On-Premise. I have registered a plugin that gets triggered when two fields are being updated: fieldA and fieldB. The plugin will encrypt both fields, but for some reason it would only update the first field: fieldA

We registered the plugin as Post-Operation. We also registered a PostImage with both fieldA and fieldB as the filter. However for some reason it would only update fieldA and not fieldB.

Here's my code. I put a 'throw new InvalidPluginExecutionException' after the assignment of fieldB, but for some reason it is never reached. If I put InvalidPluginExecutionException BEFORE the assignment of fieldB (but still inside the if condition), then I would receive the error message.

I am not sure what is wrong with the assignment...

        string fieldA;
        string fieldB;

        var targetEntity = context.GetParameterCollection(context.InputParameters, "Target");

        if (targetEntity == null)
            throw new InvalidPluginExecutionException(OperationStatus.Failed, "Target Entity cannot be null");

        var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
        var service = serviceFactory.CreateOrganizationService(context.UserId);

        if (context.Depth == 1)
        {
            var postImage = context.PostEntityImages["PostImage"];

            if (postImage == null)
                throw new InvalidPluginExecutionException(OperationStatus.Failed, "Post Image is required");

            var account = context.GenerateCompositeEntity(targetEntity, postImage);

            if (targetEntity.Attributes.Contains("new_fieldA"))
            {
                fieldA = account.Attributes["new_fieldA"].ToString();
                targetEntity["new_fieldA"] = encrypt(fieldA);
            }

            if (targetEntity.Attributes.Contains("new_fieldB"))
            {
                fieldB = account.Attributes["new_fieldB"].ToString();
                throw new InvalidPluginExecutionException("test222"); //for some reason this message never shows up
                //targetEntity["new_fieldB"] = encrypt(fieldB);
                //targetEntity["new_fieldB"] = "hello";
            }

            service.Update(targetEntity);

I have the same question (0)
  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at

    can you add tracing in this plugin at before and after the condition?

  • Ray Profile Picture
    1,537 on at

    First, I think your plugin has a infinity loop, when fieldA and fieldB get update, then your plugin update these two fields and retrigger the plugin.

    Second, I think you can try to use the Plugin Registration Tool to debug your plugin.

    BTW, I think you should create a new Entity object instand using the update object in context, this object may contains some field you do not want to update.

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    the problem is not an infinite loop (there is already a Depth check to avoid it)

    the problem is that the field is checked from the targetEntity and not from the Image, if the update is only on fieldA, the target entity will not contain the fieldB, the image will contain always both (as they are part of the Image)

    hope it helps

  • CRM1339 Profile Picture
    25 on at

    Hi Guido, thank you for the reply. I'm interested in your idea. You're correct, my PostImage contains both FieldA and FieldB as parameters. Do you suppose I should create two separate PostImage with only FieldA, and another one with only FieldB?

    Thank you.

  • CRM1339 Profile Picture
    25 on at

    Also just want to mention, when I only update FieldB, my plugin still does not get triggered anyway....

    Updating FieldA will trigger the plugin.

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at

    Can you share plugin step (create/update) which you have registered ?

  • Ray Profile Picture
    1,537 on at

    Maybe you can check you plugin step see if you only registration the plugin on fieldA, not fieldB.

  • CRM1339 Profile Picture
    25 on at

    Hi Amit, Yes please see the attached picture. Sorry I edited the pic to cover sensitive info, but both field A and B are there

    2476.Update-Plugin.PNG

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at

    can you open the given step so that we will have some more details related with the filter attributes, Also have you selected all the attributes in POST image or only some of it?

  • CRM1339 Profile Picture
    25 on at

    Hi Amit, thank you for the reply. Yes it looks like this. Thank you.7484.PostImage.PNG

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 74 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans