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);

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,407 Super User 2025 Season 1 on at
    RE: CRM Plugin Did not Update All Fields

    Happy to help you.

  • Suggested answer
    CRM1339 Profile Picture
    25 on at
    RE: CRM Plugin Did not Update All Fields

    Thank you so much everyone for all your help. I did not realize the Update plugin was only filtering fieldA and not fieldB.... It was a user error :( I did not realize it until Amit asked me to post the Update Step. Thank you so much and hope you all have a great week.

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,407 Super User 2025 Season 1 on at
    RE: CRM Plugin Did not Update All Fields

    That means your condition is not satisfied. try to put tracing before this condition. also check what is the outcome of

    targetEntity.Attributes.Contains("new_fieldB")

    and print it on trace logs.

  • CRM1339 Profile Picture
    25 on at
    RE: CRM Plugin Did not Update All Fields

    Hi Amit,

    I tried using plugin tracing for the very first time. I went to Settings > Administration > System Settings. In the Customization tab, locate the drop-down menu labeled Enable logging to plug-in trace log and select 'ALL'.

    Then I updated the code as follow. When updating either fieldA or fieldB, nothing is written to Plug-in Trace Logs. Do I wait a while or do a server restart before the logs start coming? 

    var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    var service = serviceFactory.CreateOrganizationService(context.UserId);
    
    string fieldB = "";
    
    if (targetEntity.Attributes.Contains("new_fieldB"))
    {
    	// Use the tracing service 
    	tracingService.Trace("Before assignment: "  fieldB);
    	addtlTaxId = account.Attributes["new_fieldB"].ToString();
    	tracingService.Trace("After assignment: "   fieldB);
    
    }

  • Verified answer
    Amit Katariya007 Profile Picture
    10,407 Super User 2025 Season 1 on at
    RE: CRM Plugin Did not Update All Fields

    Can you share details about below 2 steps also ?

    pastedimage1654521103109v1.png

  • CRM1339 Profile Picture
    25 on at
    RE: CRM Plugin Did not Update All Fields

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

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,407 Super User 2025 Season 1 on at
    RE: CRM Plugin Did not Update All Fields

    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
    RE: CRM Plugin Did not Update All Fields

    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

  • Ray Profile Picture
    1,485 on at
    RE: CRM Plugin Did not Update All Fields

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

  • Suggested answer
    Amit Katariya007 Profile Picture
    10,407 Super User 2025 Season 1 on at
    RE: CRM Plugin Did not Update All Fields

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

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 82 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans