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)

Plugin not triggering

(0) ShareShare
ReportReport
Posted on by 410

Hi Guys,

   I have created and registered a plugin, registered on Update and on a single field, but for whatever reason, it is not triggering, neither is it producing any form of trace log message. My plugin code is below:

if(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity )
            {
                Entity conStaffRol = (Entity)context.InputParameters["Target"];

                if (!(conStaffRol.LogicalName == "new_consultantstaffingrole" || conStaffRol.LogicalName == "new_nursestaffingrole")) { return; }

                try
                {

                    EntityReference staffRef = conStaffRol.GetAttributeValue<EntityReference>("gg_travelbooking");

                    if (context.MessageName == "update")
                    {
                        if (staffRef == null)
                        {
                            OptionSetValue conStaff = conStaffRol.GetAttributeValue<OptionSetValue>("new_plandaystatus");
                            //conStaff = new OptionSetValue(100000004);

                            if (conStaff == new OptionSetValue(100000004))
                            {
                                CreateTravelDetail(service, conStaffRol);
                            }

                        }

                    }

                }catch(FaultException<OrganizationServiceFault> ex)
                {
                    tracing.Trace("Unable to create travel Detail entity: ", ex.ToString());
                }
                catch(Exception e)
                {
                    tracing.Trace("Error :" + e.ToString());
                }

                
            }


The travelDetail() method code called can be seen below:

ivate void CreateTravelDetail(IOrganizationService service, Entity entity)
        {
            Entity travelDetail = new Entity("gg_traveldetail");
  

            if(entity.LogicalName == "new_consultantstaffingrole")
            {
                EntityReference conEntityReference = entity.GetAttributeValue<EntityReference>("new_consultant");


                Entity consultant = service.Retrieve(conEntityReference.LogicalName, conEntityReference.Id, new ColumnSet(new string[] { "new_name" }));
                travelDetail["gg_name"] = entity.GetAttributeValue<string>("new_name");
                travelDetail["gg_travellersname"] = consultant.GetAttributeValue<string>("new_name");
                travelDetail["gg_consultantstaffingrole"] = entity.GetAttributeValue<OptionSetValue>("new_role");
                Guid travelId = service.Create(travelDetail);
                entity["gg_travelbooking"] = new EntityReference(travelDetail.LogicalName, travelId);

                service.Create(consultant);

            }

            if (entity.LogicalName == "new_nursestaffingrole")
            {
                EntityReference nurEntityReference = entity.GetAttributeValue<EntityReference>("new_nurse");
                Entity nurse = service.Retrieve(nurEntityReference.LogicalName, nurEntityReference.Id, new ColumnSet(new string[] { "new_name" }));

                travelDetail["gg_name"] = entity.GetAttributeValue<string>("new_name");
                travelDetail["gg_travellersname"] = nurse.GetAttributeValue<string>("new_name");
                travelDetail["gg_nursestaffingrole"] = entity.GetAttributeValue<OptionSetValue>("new_role");
                Guid travelId = service.Create(travelDetail);

                entity["gg_travelbooking"] = new EntityReference(travelDetail.LogicalName, travelId);
                service.Create(nurse);

            }
        }
    }


I have looked thoroughly in the forum and no oneseems to have had this same problem. I am only trying to populate and create another entity record if a field in the context is equal to a specific value. Thanks for the help

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Plugin not triggering

    Hi Victor,

    Not sure if your issue is already fixed or not but here are my thoughts-

    The simplest way to check if plugin is executing or not is to throw an error on the first line (  throw new InvalidPluginExecutionException("Plugin triggered");). Personally I create a new task record and I leave that code untill my dev is completed. So if I am in doubt if my plugin is working or not, i just check if there are task created or not :)

    Also, instead of "if (conStaff == new OptionSetValue(100000004))" change to   if (conStaff != null && conStaff.Value == 100000004). Also, put an else part for this if and throw some error. this way you will know if this is going in else.

    Hope this helps.

  • Suggested answer
    rthompson Profile Picture
    1,532 on at
    RE: Plugin not triggering

    As you already know.  And optionSet Value is a int.

    Doing something like this.

               int conStaff = 100000003;

               int compareConStaff = 100000004;

               if (conStaff != compareConStaff)

               {

                   Entity["constaff"] = new OptionSetValue(conStaff);

               }

    To get a value something like this

    OptionSetValue conStaffInfo = (OptionSetValue)Entity.Attributes["constaff"];
    

    conStaff = conStaffInfo.Value;

  • Victor Onyebuchi Profile Picture
    410 on at
    RE: Plugin not triggering

    rthompson, it is throwing an error at this line  if (conStaff == new OptionSetValue( 100000004)), how do we compare an optionset value ?? isnt this way ?

  • Victor Onyebuchi Profile Picture
    410 on at
    RE: Plugin not triggering

    Yes, currently debugging it. thanks

  • Verified answer
    rthompson Profile Picture
    1,532 on at
    RE: Plugin not triggering

    Have you used start profile?

    If you have not used start profile please turn that on and it will create a log file for you.

    After you have started the profiling go back to your form and do your steps.

    Once done go to VS do a right click on your class look for  CRM > debug.

    Click the down arrow and you will see your logs.

    5670.debug.JPG

  • Victor Onyebuchi Profile Picture
    410 on at
    RE: Plugin not triggering

    You do not have to be sorry, you are only trying to help. I appreciate it. 

  • Suggested answer
    rthompson Profile Picture
    1,532 on at
    RE: Plugin not triggering

    Hi Victor,

    Sorry for all the e-mails.

    Just a suggestion.  

    In the future when dealing with plugins I find it better to explain everything I have done when creating a plugin.  This way I do not receive a lot of e-mails asking me questions on things I have already done.

    If you are at this point.  Do a start profile.  The start profile will help you find the issue that you are having in the plugin.

    Have you tried doing a start profile?

  • Victor Onyebuchi Profile Picture
    410 on at
    RE: Plugin not triggering

    rthompson 1030.image3.png

    As expected, i registered both on Update. Yes, if statement checks if it equals a certain option when updated.

  • Suggested answer
    rthompson Profile Picture
    1,532 on at
    RE: Plugin not triggering

    Stupid question?

    The field or fields that you are trying to update.  Are you changing them on the form?

    If you are not changing any of the fields on the form they will not show in the entity.  The entity will only show the field that have changed.

    Please do not ask me why they did it that way...:=)

    Please also send this screenshot.

    0121.Plugin.JPG

  • Victor Onyebuchi Profile Picture
    410 on at
    RE: Plugin not triggering

    5554.image2.png  please find the image rthompson

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
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans