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:

http://www.itaintboring.com/dynamics-crm/dynamics-crm-use-a-workflow-to-set-a-lookup/

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.

 

 

11 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?

    Thanks

    Reply
    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

      Reply
  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:

    Reply
  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:
    value=”#cosl_projectregistration#”

    Reply
    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?

      Reply
      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?

        Reply
  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”

    Thanks!

    Reply
    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/

      Reply
  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.

    Reply
  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:

    Thoughts?
    I’m not even getting any errors.

    Thanks!

    Reply
    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.

      Thanks!

      Reply

Leave a Reply

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