Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Plugin succeeds but no action

Posted on by 1,299

Hi,

I have created a plugin that will trigger on Create and Update, the plugin succeeds which i can see from the system jobs and there is no error but the activity that the plugin is intended to do it not working. I am not even sure how to debug this as there is no error too to use the profiler.

please help.

*This post is locked for comments

  • Davyjones Profile Picture
    Davyjones 1,299 on at
    RE: Plugin succeeds but no action

    HI Nuno,

    There is a place in the procedure where i need to have the exception generated stored in a txt file(error details.txt) and use the same,  but i actually dont get exceptions  at all.

    Thanks

  • Suggested answer
    Nuno Profile Picture
    Nuno 2,005 on at
    RE: Plugin succeeds but no action

    Hi,

    You do not need any error to use the profiler.

    To use the profiler with plugin registration tool you must start profilling a step of your plugin and them execute the action on crm that triggers the step and HERE is generated an exception you may use to debug your plugin. In the links I shared previous it is described the process to debug plugins with plugin registration tool.

  • Suggested answer
    abdulghaffar164 Profile Picture
    abdulghaffar164 385 on at
    RE: Plugin succeeds but no action

    Hi Davyjones

    You can add loging into your plugin as follows.

    1) Create a custom entity with name log

    2) Add a custom attribute with the name message.

    3) In your plugin just before you start your code (after the service has been created) write these lines of code.

    Entity log = new Entity("new_log");

    log["new_msg"] = "Log Message";

    _service.Create(log);

    4) Then you can let's say add another line of your custom code and put these two lines right below that code.

    log["new_msg"] = "Log Message 2";

    _service.Create(log);

    Similarly you can add as much loging into your plugin as you want. Each create statement would insert a record into your log entity.

    5) After your plugin has executed go to the advanced find and search log entity.

    6) From advanced find you can view all the records and observe the values and see where is the root cause.

    I hope this would help you!

  • Davyjones Profile Picture
    Davyjones 1,299 on at
    RE: Plugin succeeds but no action

    Hi Joe,

    Apologies, i might be asking the same question again i am very new to this. There is no error in the code at all to catch an exception, i am sying thsi because the plugin is not failing or throwing error at all. i am pasting the code that i am using for your help.

    Thanks for your patience.

    namespace CRM_to_Finance

    {

       public class Finance:IPlugin

       {

           private readonly string _unsecureString;

           public Finance(string unsecureString)

           {

               if (String.IsNullOrWhiteSpace(unsecureString))

               {

                   throw new InvalidOperationException

                       ("Unsecurestring is required by the Plugin, but not provided.");

               }

               _unsecureString = unsecureString;

           }

           public void Execute(IServiceProvider serviceProvider)

           {

               Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)

                   serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

               Microsoft.Xrm.Sdk.IOrganizationServiceFactory servicefactory = (Microsoft.Xrm.Sdk.IOrganizationServiceFactory)

                  serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IOrganizationServiceFactory));

               Microsoft.Xrm.Sdk.IOrganizationService service = servicefactory.CreateOrganizationService(context.UserId);

               if (context.InputParameters.Contains("Target") &&

                    context.InputParameters["Target"] is Entity)

               {

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

                   if (entity.LogicalName != "Opportunity")

                       return;

                   if (entity.LogicalName == "Opportunity")

                   {

               string oppid;

               oppid=entity.Attributes["new_opportunityid"].ToString();

               WebClient proxy = new WebClient();

               string strurl = "";

               strurl = _unsecureString.ToString() + oppid.ToString();

               byte[] data = proxy.DownloadData(new Uri(strurl.ToString()));

               Stream stream = new MemoryStream(data);

               DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(string));

                   }

               }

           }

       }

    }

  • Suggested answer
    Joe Gill Profile Picture
    Joe Gill on at
    RE: Plugin succeeds but no action

    Hi,

    If you read the link I posted it tells you how to add Tracing logs to your code and how to view them

    http://joegilldotcom.blogspot.co.uk/2016/07/tracing-in-dynamics-crm-custom.html#more

    If your code is not throwing an exception then your cannot capture it to debug. In which you should add the throw statement to your code to force an exception

    Joe

  • Davyjones Profile Picture
    Davyjones 1,299 on at
    RE: Plugin succeeds but no action

    Hi Nuno,

    Thanks you, but to use the profiler there should be an error, but i am not getting any error at all the plugin just succeeds.

    Thanks

  • Davyjones Profile Picture
    Davyjones 1,299 on at
    RE: Plugin succeeds but no action

    Hi Joe,

    Thanks for your response, i am not sure how to throw an exception and get it in tracing, all my plugin does is all a webservice appending the opportunity Id .

    kindly help

  • Davyjones Profile Picture
    Davyjones 1,299 on at
    RE: Plugin succeeds but no action

    Hi Abdul,

    Thanks very much

    I strongly believe what you said could be a reason, i am new to these plugins and i am not sure where i should have the above code in my plugin, and where should i go to read the logs. please help.

  • Suggested answer
    Nuno Profile Picture
    Nuno 2,005 on at
    RE: Plugin succeeds but no action

    Hi,

    Here you may find out how to debug plugins with plugin registration tool:

    www.engagesoftware.com/.../how-to-debug-a-plugin-in-dynamics-crm-2015-online

    Additionally, if you're using CRM 2015 update 1 or an earlier version you may use tracelog:

    www.magnetismsolutions.com/.../ahmed-anwar&;s-blog/2015/06/04/tracing-and-logging-plugins-in-dynamics-crm-2015-online

  • Suggested answer
    Joe Gill Profile Picture
    Joe Gill on at
    RE: Plugin succeeds but no action

    Hi,

    You could throw an exception in your code to debug it.

    Otherwise add tracing statements to help find the problem

    joegilldotcom.blogspot.ie/.../tracing-in-dynamics-crm-custom.html

    hth

    Joe

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans