Update current time and current user without using Javascript in model driven forms

Sometimes we need to capture field updates for audit purposes. Here is an example:

Account form has a field for “Account Application Status” (Options – Approved/Rejected). In either case, we need to capture who approved/rejected the application and date/time.

My first idea was to implement this using business rules. However, this cannot be implemented using standard business rule functionality as it doesn’t support current date/time function. You can have a limited number of functions within business rule actions.

I was able to implement this via a combination of calculated fields and business rules. Here are the steps:

CALCULATED FIELDS

Capture date/time for a field update

  1. Create a new date/time calculated column in the Account table (“Calc_approved/rejected on”)

2. Add the calculation logic. Set the field value to current time.

Capture the current user who modified a field

  1. Create a calculated text column(Calc_approved/rejected by)

2. Configure calculated field as below:

These calculated fields will always capture the current time and current user of a form. Now all we have to do is set the business rules to update the tracking fields when the status changes.

BUSINESS RULES – Business rules are running on the UI actions therefore when a field is updated by the user, we can trigger a business rule. Since we already have current values coming in from the calculated fields, we can simply map the values in the business rule.

  1. Create a date/time field ” Approved/Rejected On”
  2. Create a text field “Approved/Rejected By”
  3. Add both these fields to the Account main form
  4. Go to “Account” table and navigate to Business rules tab

Approved/rejected date/time update rule

Condition: when approval status is updated
Action : set the Approve/Rejected time as per calculated field

Configure the same action for the other branch. (Since we need to track the rejected date/time as well)

Approved/rejected user update rule

Create another business rule. Condition is the same as we are setting field values when the status field is getting updated.

Add the set field action and update approved/rejected by field with the value of calculated field.

Now save and activate both business rules.

Let’s test the form..

The form is now auto capturing approved time and approver name.

Considering data integrity, we can make these fields read-only so that users will not be able to change these fields manually.

In summary, what we did was to calculate current time and current user and assign those field values in business rule actions.

Hope this low code solution will help you in your design process.

Happy Learning!



Categories: Dynamics 365, PowerApps

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: