How to Debug

Jan 27, 2015 at 5:19 PM
Edited Jan 27, 2015 at 5:21 PM
I installed the package. on CRM 2015 Online. But: my thing's crashing and I don't know how to get details.

I'm trying to create a plugin that will sum up a numerical value for a related entities. In my case, I have a Contact with a related custom entity called Expense. I want the sum of all Expenses to live on the Contact. (I can't use a regular rollup field for this since there is a requirement for a specific filter not available in the OOTB config.)

I set it up as a scheduled plugin.

On the left side, I have a Fetch to give me all the Contacts, and all the Expenses. It gives me #p2 and #p3, as Foreach. Good so far.

The first thing I need to do is to zero out the sum value on each Contact. So my action is "Update of Contact", condition is #p3[0] > 0, where id = #p3[contactid] (contact). (Presumably this means all records returned by the Fetch.) I then go ahead and set my_expensesum to 0.

I set this to run with Start Date = a few minutes from now. When it runs, I get: "Task Terminated".

Online, I've found a few links like this. My first issue is that this, as a scheduled activity, does not appear in the Plugin Registration Tool, so how do I profile it?

Generally speaking, what are best practices for debugging?
Jan 27, 2015 at 8:07 PM
OK so I figured out how to execute on this without doing a brute force update. Basically I set up a plugin to update the Contact whenever an associated Expense is changed, and I got around a date/time requirement with a periodic function.

But the question remains, what is the best way to debug processes with this tool?
Jan 28, 2015 at 2:03 PM
Hi Bob,

It's the right way to 'sync' a contact field with its Expenses sum :)
Please let me know if you have problems for settting it (Just export your configuration, and post it here)

Generally, you can not really debug EasyPlugins (You need Code Source for that, and it REALLY hard to debug)
A good alternative is to :
  • Create a test plugin (not scheduled) that triggers on Post Update Contact
  • Then Set parameters to debug (FetchXml, fields, ...)
  • Create an "Abort Message" that contains the data you want to display
  • Open a contact form, change it then save...
Example : You want to 'debug' this FetchXml :
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="opportunity">
    <attribute name="estimatedvalue" />
    <order attribute="name" descending="false" />
    <filter type="and">
      <condition attribute="parentaccountid" operator="eq" uitype="account" value="{9AB904F2-FDA6-E411-A5F8-00155D013602}" />
Import this Configuration to Debug it :
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfXportObject xmlns:xsi="" xmlns:xsd="">
  <XportObject Name="Test Debug (imported)" Active="false" Entity="contact" PreCreate="false" PostCreate="false" PreUpdate="false" PostUpdate="true" PreDelete="false" PostDelete="false" Synchronous="true" Order="1" TriggerType="0" IsPeriodic="false" Period="0" PeriodUnit="0" StartDate="0001-01-01T01:00:00+01:00">
    <Rules>&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfCrmRule xmlns:xsi="" xmlns:xsd=""&gt;
  &lt;CrmRule ParamNumber="1" Type="Request" AttributeState="After" AttributesReturnTypes="None" ReturnCount="1" ReturnType="Number" LogicalName="" FetchXml="&amp;lt;fetch version=&amp;quot;1.0&amp;quot; output-format=&amp;quot;xml-platform&amp;quot; mapping=&amp;quot;logical&amp;quot; distinct=&amp;quot;false&amp;quot;&amp;gt;&amp;#xD;  &amp;lt;entity name=&amp;quot;opportunity&amp;quot;&amp;gt;&amp;#xD;    &amp;lt;attribute name=&amp;quot;estimatedvalue&amp;quot; /&amp;gt;&amp;#xD;    &amp;lt;order attribute=&amp;quot;name&amp;quot; descending=&amp;quot;false&amp;quot; /&amp;gt;&amp;#xD;    &amp;lt;filter type=&amp;quot;and&amp;quot;&amp;gt;&amp;#xD;      &amp;lt;condition attribute=&amp;quot;parentaccountid&amp;quot; operator=&amp;quot;eq&amp;quot; uitype=&amp;quot;account&amp;quot; value=&amp;quot;{9AB904F2-FDA6-E411-A5F8-00155D013602}&amp;quot; /&amp;gt;&amp;#xD;    &amp;lt;/filter&amp;gt;&amp;#xD;  &amp;lt;/entity&amp;gt;&amp;#xD;&amp;lt;/fetch&amp;gt;" LineFunction="Sum" LineSeparator="" ColumnSeparator="" /&gt;
    <Actions>&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfCrmAction xmlns:xsi="" xmlns:xsd=""&gt;
  &lt;CrmAction Type="Abort" MaxDepth="1" ForEachParamNumber="-1" EntityLogicalName="" Order="0"&gt;
    &lt;Expressions /&gt;
    &lt;ExpressionId AttributeLogicalName="" Type="String" Expression="#p1.ToString() + &amp;quot; is the sum&amp;quot;" AttributeTypeCode="String" Targets="" /&gt;
    &lt;ConditionExpression AttributeLogicalName="" Type="Boolean" Expression="true" AttributeTypeCode="Boolean" Targets="" /&gt;
Jan 29, 2015 at 5:03 PM
Thank you! I'm learning that the best way to debug is to set the process to synchronous so you get the process to throw errors at runtime. I think part of my problem was that I was going for scheduled processes right off the bat.

Thank you for this explanation, I understand what you're saying and hopefully this can help future users.

I have created a few blogs that explain what I did in detail - once they're published I'll link them here. I tried to explain some of the things that are not obvious to beginners, like how to read an option set value.