How to clone a record and set its lookup field to new parent in Dynamics 365 CE

Posted by

I would like to create a copy of an existing “template” record (custom entity) and then set the lookup on the new record to a parent, in this case the account from where I start the on-demand workflow.

With the help of Demian Raschkovan’s Dynamics-365-Workflow-Tools I am able to clone a record.

And with the help of Andrew Butenko’s Ultimate Workflow Toolkit I can set the lookup field on the cloned record. First I use the workflow activity UWT: Request Builder > Set Lookup Field to set the Field Value with the Record URL of the Account and the Field Name (internal value) from the entity of the cloned record that should be updated.

Finally with the workflow activity UWT: Bulk Operations > Update Records I can update the “requested” lookup field at the cloned record that I fetch with its Guid in the FetchXml Query.

So now by starting the on-demand workflow from an account, a copy of the template record is created and linked to the account.

Easy peasy, thanks to our workflow heroes Demian and Andrew. Cheers!

2 comments

  1. This is great information. Unfortunately, I am struggling with step 3. I am trying to clone a D365 Field Service Work Order and then set it as the parent of the created clone.

    I get this message:
    An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute): UltimateWorkflowToolkit.CoreOperations.BulkOperations.UpdateRecords: System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.

    Hopefully, I will eventually figure it out!

    1. Hi Christine,
      Did you set the Field Name in step 2 to: msdyn_parentworkorder
      and the FetchXml Query in step 3 to:

      FetchXML Query

Leave a Reply

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