Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Cannot debug custom activity in workflow

Posted on by 2,397

I have a custom workflow activity that I am trying to debug using the Plugin Registration Tool. When I run the workflow, I see it appear in System Jobs. Within a few seconds the status changes from 'In Progress' to 'Waiting' and when I open the job, the Details section contains the following:

2017_2D00_10_2D00_17_5F00_0838.png

But if I am not profiling the workflow, then the activity runs correctly and updates the selected contact record as expected.

I've seen a few posts online from people who have had the same problem but cannot see any solutions. Does anyone have any ideas? All I have just one input entity, no output parameter,

2017_2D00_10_2D00_17_5F00_0840.png

*This post is locked for comments

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Cannot debug custom activity in workflow

    I would suggest to add traces after every single line which can cause exception. In that way you can define what line causes exception. Good luck.

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: Cannot debug custom activity in workflow

    Hi, I got the same error message. It is still under testing, since I can not get into the debugger, I have to trace the error in this way. 

    2017_2D00_10_2D00_17_5F00_1148.png

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Cannot debug custom activity in workflow

    Try to replace line

    if (result < decimal.Parse(totalamount.ToString()))

    with line

    if (result < totalamount.Value)

    I'm just curious - your workflow activity will fail anyway because you have this weird part of code:

                   if (result < decimal.Parse(totalamount.ToString()))

                   {

                       throw new InvalidPluginExecutionException("Payment is not completed");

                   }

                   else

                   {

                       throw new InvalidPluginExecutionException("Payment is completed");

                   }

    It will throw an exception in any case - is it expected behavior?

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: Cannot debug custom activity in workflow

    Sure, here you go

     [Input("Input Entity")]
            [RequiredArgument]
            [ReferenceTarget("invoice")]
            public InArgument<EntityReference> InputEntity { get; set; }
            public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext)
            {
                //Create the tracing service
                ITracingService tracingService = executionContext.GetExtension<ITracingService>();
                //Create the context
                IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
                IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                decimal result = 0;
    
                if (crmWorkflowContext == null)
                {
                    throw new ArgumentNullException("crmWorkflowContext");
                }
    
    	        try
    	        {
                    //get old invoice id
                    if (this.InputEntity.Get(executionContext).Id == null)
                    {
                        throw new InvalidPluginExecutionException("Failed to retrieve invoice id.");
                    }
                    string totalPaymentItems = @" <fetch distinct='false' mapping='logical' aggregate='true' >
                                                   <entity name='recoserv_paymentitem' >
                                                      <attribute name='recoserv_amount' alias='recoserv_amount_sum' aggregate='sum' />
                                                       <filter type='and' >
                                                        <condition attribute='recoserv_invoice' operator='eq' value='"+ this.InputEntity.Get(executionContext).Id + @"' />
                                                       </filter>
                                                   </entity>
                                                  </fetch>";
                    EntityCollection sumResult = service.RetrieveMultiple(new FetchExpression(totalPaymentItems));
                    var invoice = service.Retrieve("invoice", this.InputEntity.Get(executionContext).Id, new ColumnSet(true));
                    Money totalamount = invoice.GetAttributeValue<Money>("totalamount");
                    foreach ( var c in sumResult.Entities)
                    {
                         result = ((Money)((AliasedValue)c["recoserv_amount_sum"]).Value).Value;
                    }
                    if (result < decimal.Parse(totalamount.ToString()))
                    {
                        throw new InvalidPluginExecutionException("Payment is not completed");
                    }
                    else
                    {
                        throw new InvalidPluginExecutionException("Payment is completed");
                    }
    
                }
                catch (FaultException<OrganizationServiceFault> e)
                {
                    tracingService.Trace("Exception: {0}", e.ToString());
                    tracingService.Trace("Timestamp: {0}", e.Detail.Timestamp);
                    tracingService.Trace("Code: {0}", e.Detail.ErrorCode);
                    tracingService.Trace("Message: {0}", e.Detail.Message);
                    tracingService.Trace("Trace: {0}", e.Detail.TraceText);
                    throw e;
                }
            }


  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Cannot debug custom activity in workflow

    Can you please provide full code of your custom workflow activity?

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: Cannot debug custom activity in workflow

    I still got the same error message

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Cannot debug custom activity in workflow

    Hello,

    Try to use "invoice" instead of Invoice.EntityLogicalName and check if it works.

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