Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

update plugin doesn't get triggered

Posted on by 2,397

Hi, I created a simple plugin to update contact record. Basically, it should clear all the flags from associated records, and set a new flag in one record. It is "Update" message on contact, pre-operation, however, it doesn't triggered at all. please check the below,

            if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity)
            {
                Entity entity = (Entity)context.InputParameters["Target"];
                if (entity.LogicalName == "contact")
                {
                    if (entity.Attributes.Contains("businessregistrationid") == true)
                    {
                        String contactid = entity.Id.ToString();
                        string registraionid = entity.Attributes["businessregistrationid"].ToString();
                        string fetchxml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                            <entity name='contact'>
                                            <attribute name='businessregistrationid' />
                                            <attribute name='record' />
                                            <attribute name='contactid' />
                                            <filter type='and'>
                                                <condition attribute='businessregistrationid' operator='eq' value='"+registraionid+@"'/>
                                            </filter>
                                            </entity>
                                           </fetch>";
                        EntityCollection ec = service.RetrieveMultiple(new FetchExpression(fetchxml));

                        foreach (var c in ec.Entities)
                        {
                            if (c.Attributes["record"].ToString() == contactid)
                            {
                                c.Attributes["record"] = "1";
                            }
                            else
                            {
                                c.Attributes["ofrecord"] = "0";
                            }

                        }
                    }

                }
                else { throw new InvalidPluginExecutionException("The account number can only be set by the system."); }
            }


*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: update plugin doesn't get triggered

    Hi Sdnd,

    Have you registered Plugin Step for your plugin after registering Plugin Assembly ?

    Plugin Step is required to make plugin triggered.

    Please mark as verified if this helps.

    Thanks,

    Himanshu Prajapati

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: update plugin doesn't get triggered

    Hi,

    In order to confirm whether the plugin gets triggered or not, you could try throwing an exception by replacing the plugin code as shown below.

    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {
                    Entity entity = (Entity)context.InputParameters["Target"];
                    if (entity.LogicalName == "contact")
                    {
                        throw new InvalidPluginExecutionException("The plugin registered on the pre operation of contact is triggered");
                    }
                }

    Hope this helps.

  • Verified answer
    Jeyaharan Sarma Profile Picture
    Jeyaharan Sarma 55 on at
    RE: update plugin doesn't get triggered

    Hi sdnd,

    The better solutions is to throw new InvalidPluginExecutionException("some text here") in each condition checks. So you know where the logic is failing.

    Also make sure you selected the update attributes when registering the plugin step.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: update plugin doesn't get triggered

    Instead of throwing error you can try to use the plugins trace log to step through your plugins code, www.powerobjects.com/.../debugging-your-plug-ins-with-the-plug-in-trace-log

    If you going to update associated records you need to call the service.update(c) otherwise it is just setting the value to entity and not doing anything else.

  • Verified answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: update plugin doesn't get triggered

    Hi

    If you do not want to use profiler, simply add exception at the top of (inside) your Execution function. So, that it would throw 'Business Process Error' with the error message (Example: "Contact update plugin triggered"). This way you can find out that the plugin is triggered.

    throw new InvalidPluginExecutionException("Contact update plugin triggered. 2017/06/07 22:21");
    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) {


  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: update plugin doesn't get triggered

    Now I got the error log, but after I put it in the profile, it still gave me the below error, and can not move on.

    1351.2017_2D00_06_2D00_06_5F00_1026.png

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: update plugin doesn't get triggered

    If there is no error message (if you mean that throw new...), then it's probably not registered correctly. How did you register the step?

    As for the debugging.. If it's on-prem, this would help:

    msdn.microsoft.com/.../gg328574.aspx

    Otherwise, either use those exceptions for "quick" debugging, or have a look at the plugin profiler:

    dynamics365blocks.wordpress.com/.../how-to-debug-a-plugin-in-dynamics-365-online-using-plugin-profiler

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: update plugin doesn't get triggered

    Hi, Alex,

    How to debug this, since there is no error message

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: update plugin doesn't get triggered

    Hi sdnd,

      are you sure it does not get triggered? If you add

     

      throw new InvalidPluginExecutionException("test");

      right at the beginning, will you see an error message?

     

      If it does not get triggered, you need to look at the registration (step, attributed, etc)

      If it does get triggered but is not doing what it should, this line looks suspicious:

    if (entity.Attributes.Contains("businessregistrationid") == true)

    Is there an attribute with that schema name in the contact entity? ("businessregistrationid")

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans