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 may be NSFW.
Clik here to view.
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 may be NSFW.
Clik here to view.
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 may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Secondly, the Workflow Process is configured to start automatically After a Contact is created or the designated Contact fields change.
Image may be NSFW.
Clik here to view.
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 may be NSFW.
Clik here to view.
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 ModifiedBy 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 may be NSFW.
Clik here to view.
It is a straight forward task to configure the Last Updated On field to be set to the Process ExecutionTime. 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 may be NSFW.
Clik here to view.
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 may be NSFW.
Clik here to view.
After the Workflow Process has been configured and activated it can be tested.
Create New Contact
I will now create a new Contact.
Image may be NSFW.
Clik here to view.
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 may be NSFW.
Clik here to view.
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 may be NSFW.
Clik here to view.
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 may be NSFW.
Clik here to view.
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 may be NSFW.
Clik here to view.
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 may be NSFW.
Clik here to view.
However, Microsoft Dynamics 365 always updates the Modified On and Modified By fields whenever a Contact is updated.
Image may be NSFW.
Clik here to view.
Clik here to view.