How to Set a User Lookup Field to the Current User Using a Workflow Process in Microsoft Dynamics 365 - Part 1

Colin Maitland, 11 October 2017

In this article, I will demonstrate how to configure a Workflow Process to set any User Lookup field to the Current User. The techniques demonstrated in this article also apply to the use of Dialogue Processes and Actions.

In part two of this article I will provide additional important information that you should be aware of.

Scenario

The Modified On and Modified By fields for Contacts are always automatically set by Microsoft Dynamics 365 whenever any field on the Contact is changed.

However, Adventure Works wants to analyse, use and report on when and by whom any of a few designated Contact Information fields such as Name, Job Title, Account Name/Company, Email, Business Phone, Mobile Phone, Preferred Method of Contact and Address were last changed.

In addition, from time to time, Adventure Works may want to reconfigure the list of designated fields.

Solution

To meet these requirements the following new fields have been added to the Contact entity. These fields will be used to record the Last Updated On and Last Updated By information for a Contact.

image

These fields have also been added to the Contact form as Read-Only fields so that they can be viewed but not updated by Users.

image

A Workflow Process will be used to set the Last Updated On and Last Updated By fields when required.

Note: It is possible to use a Plugin Process instead, but this is less configurable than a Workflow Process and the aim of this article is to demonstrate how this can be done using a Workflow Process.

Note: The Last Updated On and Last Updated By fields do not need to exist on the Contact form in order for them to be updated by a Workflow Process. However, if they do they should not be Read-Only when configuring the Workflow Process otherwise you will not be able to configure them within the Update step of the Workflow Process. If required, you can temporarily remove these fields from the form or make them not Read-Only, configure the Workflow Process and then re-add the fields to the form and/or make them Read-Only again; remembering to publish the changes to the form each time.

Firstly, the Workflow Process is configured to run as a Real-Time instead of as a Background Workflow Process.

image

image


Secondly, the Workflow Process is configured to start automatically After a Contact is created or the designated Contact fields change.

image

Thirdly, the Workflow Process is configured to update the Last Updated On and Last Updated By fields on the Contact to the current Date/Time and User using a single Update Contact step.

image

Workflow Processes do not provide a direct means to obtain and use the UserId of the current User. However, the following demonstration will show how this can be done using the Contact Modified By field. The Process only provides the ability to obtain and use Activity Count, Activity Count Including Process and Execution Time. The most useful of these is Process Execution Time.

image

It is a straight forward task to configure the Last Updated On field to be set to the Process Execution Time. The Process Execution Time will be the current Date and Time when the Update step in the Workflow Process runs. The following image shows the configuration of the Last Updated On field within the Update step.

image

It is also a straight forward task to set the Last Updated By field to the Contact Modified By field. This approach works because the Modified By field will be automatically updated by Microsoft Dynamics 365 whenever a Contact is created or updated to the User who created or updated the Contact; i.e. the Current User. The following image shows the configuration of the Last Updated By field within the Update step.

image

After the Workflow Process has been configured and activated it can be tested.

Create New Contact

I will now create a new Contact.

image

As a result, the Workflow Process was automatically started and correctly set the Last Updated On and Last Updated By fields to the current Date/Time and User.

image

Update Existing Contact

Another User now updates one or more of the designated fields on the Contact, such as the Job Title and Preferred Contact Method:

image

As a result, the Workflow Process was automatically started and updates the Last Updated On and Last Updated By fields to the current Date/Time and User.

image

Finally, a user updates one or more fields that are not any of the designated fields on the Contact, such as their Contact Preferences for Follow Email, Bulk Email and Fax:

image


As a result, the Workflow Process is correctly not automatically started and so the Last Updated On and Last Updated By fields are correctly not updated.

image

However, Microsoft Dynamics 365 always updates the Modified On and Modified By fields whenever a Contact is updated.

image