Dynamics CRM (TCS Tools): Use a workflow to update related entities

By | April 24, 2017

If you read my previous post, you know how you can use TCSTools Lookup Setter custom worfklow activity to find a lookup value using a fetchxml query:


Let’s imagine a different scenario. What if you had an account and related contacts, and what if you wanted to push a field value you just entered on your account record to all of those contacts?

That is also easy to do, you just need to read that post above, and, then, think of it in reverse.

Here is what you would need to do:

  • User Advanced Find to create FetchXml that will return all contacts related to a particular account (pick any account when doing it)
  • Download FetchXml from the Advanced Find
  • Replace the id of that account in the parentcustomerid condition with “#accountid#”
  • Create a Lookup Configuration record (it’s the entity which comes with TCS Tools), and make sure to use “Fetch Result” for the direction. That will instruct the custom workflow activity that it actually need to update the records returned from the fetch (and not the record for which that worfklow has started)
  • Create a workflow for the account entity, and use Lookup Setter (paired with the Lookup Configuration created above) to update all those related contacts

Below are a few screenshots.

Here is my lookup configuration record:

  • Update direction = Fetch Result (meaning that fetch result records will be updated)
  • Fetch Result Attribute is set to “tcs_accountnumber” (this is the field that’ll be updated)
  • Entity Attribute is set to “accountnumber” (this is the field on the account record that will be used to update fetch result records)
  • Finally, FetchXml is constructed is such a way that it will get all the contacts where my current account record is added as a parent customer


Here is the workflow that will update related contacts – we are only interested in the highlighted step right now. Two other steps are interesting as well, but I will explain what they do in the next posts.

And, of course, just so you could see how that step is configured, here is the last screenshot:

That’s it, really. What this workflow will do, it will push account number updates from the account record to the related contact records (where I have a custom field called “tcs_accountnumber”).

By the way, did you notice something? You don’t really need to define a relationship between two entities to use this custom workflow activity. As long as you can define your fetchxml in such a way that it will return required records (maybe based on the email address.. based on the city name.. or simply based on the date interval), you can use this custom workflow activity to update all those records.

Just keep in mind that you probably don’t want to update thousands of records every time – performance can easily become an issue for this kind of mass updates.



14 thoughts on “Dynamics CRM (TCS Tools): Use a workflow to update related entities

  1. Ben

    Hi Alex,

    Looks great, however when i try to set up the workflow, i miss “lookup setter” in the list, i have only “attribute setter” available in the list.
    Any idea?


    1. Alex Shlega Post author

      Hi Ben,

      use attribute setter. There was a bit of renaming lately:) Since it’s not, really, just a lookup setter.. you can use it for any attribute

  2. Megan Walker

    Hi Alex, wonder if you can point me in the right direction? I am getting the following error:
    Plugin Trace:

    [TreeCatSoftware.Dynamics.TCSTools: TreeCatSoftware.Dynamics.TCSTools.Activities.CustomActivity]
    [TCS Tools: Attribute Setter]

    Error Message:
    Unhandled Exception: Microsoft.Xrm.Sdk.InvalidPluginExecutionException: An exception System.FormatException was thrown while trying to convert input value ‘#cosl_projectregistration#’ to attribute ‘opportunity.cosl_projectregistration’. Expected type of attribute value: System.Guid. Exception raised: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

    This is my FetchXML:

  3. Megan Walker

    Guessing the FetchXML got stripped out. The condition attribute in the filter of the query is condition attribute=”cosl_projectregistration” . So I set the value to this:

    1. Alex Shlega Post author

      Hi Megan,

      it seems that #cosl_projectregistration# did not get replaced with the id (might be missing in the fetch results.. or have a different name?). Could you send me a screenshot (or fetch) of that expression to ashlega@yahoo.com?

      1. Markus Ranta

        Nice work in creating the plugin! I’m trying to populate a custom attribute from Address to an Order and I’m getting similar message as above: “An exception System.FormatException was thrown while trying to convert input value ‘#billto_addressid#’ to attribute ‘customeraddress.customeraddressid’. Expected type of attribute value: System.Guid. Exception raised: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).”

        What was the resolution to the above question by Megan?

  4. Joseph

    Hi Alex,

    I’ve been trying to achieve something and was hoping to accomplish it using attribute set, but i cant seem to figure it out. Pls confirm whether its possible, perhaps you could provide some sort of guidance.

    I would like to lookup the “case number” (ticketnumber) of a case that meets the following two criteria’s 1)The status reason is “in-progress” 2)the owner is the current user (Owner = Current User). I then want to take that value (the case number) and pass it into a custom field on all cases in a “waiting” status and Modified On “Last x minutes”


    1. Alex Shlega Post author

      Hi Joseph,

      it’s probably doable, though it might be better to do some custom development instead. With TCS Tools what you might try is create two attribute setters:

      – The first one will, on some event(looking at the description you provided, I am not sure what the event is) use a fetch query to find that case, and, then, to set some field value there (maybe just a dummy datetime field which you can create for this purpose.. the idea is to create a trigger for the second attribute setter below)
      – The second one will trigger on update of the field above, and will use another fetchxml query to find all those cases in waiting status and modified on “last x minutes”, then it will set a custom field there to the case number of the case: http://www.itaintboring.com/dynamics-crm/dynamics-crm-tcs-tools-user-a-workflow-to-update-related-entities/

  5. Joseph

    Hi Alex,

    Thanks for the info. The initial event/trigger will be a change in the case status. The objective is that if Case “1234” changed the status to “In-Progress”, then update a custom field on all other cases in the in-progress status to 1234. Lets call the custom field “LastCaseNumber”

    Im not sure im understanding, how will the second attribute setter retrieve the value (case number) which the first attribute setter retrieved.

  6. Jen

    Hi Alex-

    I’ve been dying to try this and think everything is set up correctly, but nothing is happening. DYN365 environment, not 9.0 yet.

    Both fields on Account and Contact are named the same mag_xmscustomertype, used Fetch Result. Here’s the XML:

    I’m not even getting any errors.


    1. Alex Shlega Post author

      Hi Jen,

      it seems XML usually disappears when posted here – if you want, feel free to drop me an email at ashlega@yahoo.com. Please also add the screenshot of how the expression has been set up.


  7. Johan

    Hi Alex,
    I’ve been using this plugin for quite a while now with all kinds of pleasure.
    My latest quest does puzzle me however. The XML code I entered is straight on, a condition of one attribute equals a hashtagged value from the source entity.
    Then I got this nasty error message:
    “An exception System.FormatException was thrown while trying to convert input value ‘1125,00’ to attribute ‘invoice_amount_base’. Expected type of attribute value: System.Decimal. ”
    But, but, but (here comes the blind panic) both fields have data type Money!

    Could it be that the hashtagged value changes its data type in your plugin? Or why does the system expect System.Decimal in a money field?

    Any thoughts?

    1. Alex Shlega Post author

      Hi Johan, just noticed your comment. Just so I know how bad it is and whether it’s “fixable”… are you on v9 or is it for v8?

  8. Coolie

    Do you have an up-to-date example using Flow to create/update related account entity when a new contact is added? In my case the new/updated contact is read from a Web API on a schedule, and the record is created OK. However I cant work out how to relate to the account as this requires a GUID for the ‘Row ID’ and all I have is the client ID.


Leave a Reply

Your email address will not be published. Required fields are marked *