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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

service.update plugin error

(0) ShareShare
ReportReport
Posted on by 2,665

Hi,

I have a plugin that is registered on update message post operation. I am doing some related record associations and everything works correct. Except that the field(status) on the entity that plugin is triggered needs to be updated to a value so that we know plugin has worked correctly. Its a lookup field and I am updating something like this:

Entity entity = (Entity)context.InputParameters["Target"];

 if (context.PrimaryEntityName == "new_case")
                {
                    if (entity.Contains("new_trigger"))
                    {
                        try
                        {

//some code here and then..

 EntityReference incidentstatusId = new EntityReference("new_status", someGuid);
                                entity.Attributes["new_incidentstatus"] = incidentstatusId;
                                service.Update(entity);

}

}

}

So instead of updating the field value at the end of plugin execution, it is throwing this error.

This workflow job was canceled because the workflow that started it included an 
infinite loop. Correct the workflow logic and try again.

What could be the reason? Is it because service.update again triggers the same plugin?
someone please guide me through this. Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at
    RE: service.update plugin error

    Hi Roxanna,

    The problem is that your update is causing the plugin to be called again.

    You will need to either exclude the updated field from the triggering attributes on the plugin step (see crmtipoftheday.com/.../avoid-unnecessary-plugin-execution) or check the depth of the context and only execute if the depth is equal to 1.

    if (context.Depth > 1) { return; }

    See msdn.microsoft.com/.../microsoft.xrm.sdk.iexecutioncontext.depth.aspx

    Hope this helps

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at
    RE: service.update plugin error

    Hi Roxanna,

    What Scott said is correct. Your code is running continuously.

    I would suggest please go for PreUpdate or PostUpdate concept and call your method accordingly.

    Dont update the entity directly try to create new instance and update.

    Hope this helps you !!

    Thanks
    Hemant

  • crmprogrammer2013 Profile Picture
    2,665 on at
    RE: service.update plugin error

    Thanks Scott. That's very informative.

    I've excluded all the unnecessary field in triggering attributes and put in a condition for checking context.Dept. It worked like a charm.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans