locked
Failed to Debug Custom Workflow RRS feed

  • Question

  • Hello,

    I have a custom workflow that is working fine in CRM 2013 on-premise. However sometimes the workflow is not doing what it's supposed to do so we decided to debug it.

    First of all we try remote debugger, however unfortunately the developer machine is not within the same subnet with the CRM server... so this is not an option.

    So I came across this article to debug with the plugin registration tool

    http://blogs.microsoft.co.il/rdt/2013/03/08/debugging-workflow-custom-activities-with-plugin-registration-tool/#comment-2823856

    I manage to go through step# 10 to view the Plugin Profiler on CRM extension. After running the workflow, there is nothing on the list of “Active Plug-in Profiles” or anywhere else. I checked the system job - turned out the workflow is in ‘waiting’ process. Below is a portion the error message that I have. Funny because running the workflow by itself doesn’t give this error message. It’s only when we try to profile it…

    Unhandled Exception: System.Activities.InvalidWorkflowException: The following errors were encountered while processing the workflow tree:
    ‘DynamicActivity’: The private implementation of activity ’1: DynamicActivity’ has the following validation error: Compiler error(s) encountered processing expression “DirectCast(CustomActivityStep19: Step_1_converted, System.String)”.
    Syntax error in cast operator; two arguments separated by comma are required.
    
    ‘DynamicActivity’: The private implementation of activity ’1: DynamicActivity’ has the following validation error: Compiler error(s) encountered processing expression “CustomActivityStep19:Step_1_converted”.
    End of expression expected.
    
    ‘DynamicActivity’: The private implementation of activity ’1: DynamicActivity’ has the following validation error: Compiler error(s) encountered processing expression “CustomActivityStep19: Step_1″.
    End of expression expected.


    Then I came across a question on StackExchange that this might be an error on the debugger itself... Could someone please confirm? If yes, what is another way to debug my custom workflow?



    • Edited by triangular Tuesday, October 14, 2014 8:53 PM prettify
    Tuesday, October 14, 2014 8:15 PM

All replies

  • hi,

    I vaguely remember seeing an error field in async operations filtered view. It shows some details - not a very detailed one. Please check.

    regards

    Jithesh

    Tuesday, October 14, 2014 10:05 PM
  • Hi Jithesh, thanks for your reply.

    You mean the "System Job" view? Yes that's how I get the error message on below screenshot.

    Tuesday, October 14, 2014 10:14 PM
  • what I meant was in SQL server, there is a view called filteredAsyncOperation. Again, I am not 100 percent sure, I will check and let you know oncei get to an instance.

    regards

    Jithesh

    Tuesday, October 14, 2014 10:21 PM
  • Got it, thanks Jithesh. I looked in this AsyncOperation table, but  I think since the workflow is in 'waiting' status, it doesn't even get written into this table.

    Not sure why, the workflow is stuck in Waiting status only if we turn on the Workflow profiler from Plugin registration. Otherwise it is running fine..

    Thanks.


    • Edited by triangular Tuesday, October 14, 2014 10:33 PM
    Tuesday, October 14, 2014 10:32 PM
  • You can use ITracingService to generate log for your and it should help you to troubleshoot your issue.

    Microsoft Dynamics CRM Training|Our Blog | Follow US | Our Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Wednesday, October 15, 2014 3:45 AM
    Moderator
  • Hi Mahender, thanks for the reply.

    I try using Tracing service in my code. However the challenge is that the code is working well and does not produce exception. So I tried to create a 'fake' exception like division by zero below, but it's still not giving me any exception.

    My goal is to output the values of the fields passed by the workflow into the Tracing message.

    Any ideas how to create a 'dummy exception' to pass these Tracing messages?

    Thanks.

    protected override void OnExecute(CodeActivityContext codeActivityContext, IWorkflowContext context)
            {
                try
                {
    		Trace = executionContext.GetExtension<ITracingService>();
                    ServiceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
                    Trace.Trace("My Workflow Started");
    
                    var systemUser = SystemUser.Get<EntityReference>(codeActivityContext);
    
                    Trace.Trace("systemUser: " + systemUser);
    
                    var team = Team.Get<EntityReference>(codeActivityContext);
    
                    Trace.Trace("team: " + team);
    
    
                    int test = 15;
                    int test1 = 0;
                    int test2 = test / test1;
                    
                }
                catch (Exception ex)
                {
                    Trace.Trace("Error executing My Workflow. " + ex.Message);
    
                } 
            }

    Thanks.

    Wednesday, October 15, 2014 7:30 PM
  • You need to use throw new InvalidPluginExecutionException to throw exception manually.

    Microsoft Dynamics CRM Training|Our Blog | Follow US | Our Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Friday, October 17, 2014 2:44 AM
    Moderator
  • Thanks Mahender. I tried for a few hours with InvalidPluginExecutionException but unfortunately no luck yet.

    Some questions:

    1) Is InvalidPluginExecutionException working for a custom workflow code? My workflow keeps getting executed successfully and I'm not seeing any error messages being popped up or printed on the trace. See my codes below and note the InvalidPluginExecutionException

    2) What error level in order for custom workflow traces to show up in CRM log files? I used Verbose and not getting anything.

    3) Which specific CRM server log files should the trace messages be printed to? CrmAsyncService or w3wp CRM Web files?

    4) Brief summary about my workflow, it runs on a creation of Task record. Using FetchXML, the custom workflow code checks whether the Task is owned by a Team. If the owner of the parent Case belongs to the same Team, then assign the Task to the parent Case owner instead.
    We are just trying to print out the value of this Task Team vs. Case Owner into trace files or error messages, in order for us to double check.

    protected override void OnExecute(CodeActivityContext codeActivityContext, IWorkflowContext context)
            {
                try
                {
    		Trace = executionContext.GetExtension<ITracingService>();
                    ServiceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
                    Trace.Trace("My Workflow Started");
    
                    var systemUser = SystemUser.Get<EntityReference>(codeActivityContext);
    
                    Trace.Trace("systemUser: " + systemUser);
    
                    var team = Team.Get<EntityReference>(codeActivityContext);
    
                    Trace.Trace("team: " + team);
    
    
                    throw new InvalidPluginExecutionException("My Workflow is throwin error");
                    
                }
                catch (Exception ex)
                {
                    Trace.Trace("Error executing My Workflow. " + ex.Message);
    
                } 
            }
    

    Thanks much.


    • Edited by triangular Friday, October 17, 2014 11:34 PM detail
    Friday, October 17, 2014 11:33 PM