How to set Owner field dynamically using Power Automate CDS Connector (Current Environment)

By | January 25, 2021

Introduction

We previously experienced How to set or map null values in the Lookup Field using Power Automate CDS Connector. Let us explore How to set the Owner field dynamically using Power Automate.

Scenario: On the Contact entity, there exists an owner field and we want to set the same owner (which can be a user or a team) on the Opportunity entity while creating a new Opportunity. As we know how to set the lookup field, setting the Owner field is quite tricky. We need to add some extra effort with additional expressions while mapping the owner field since the owner can be a User or Team. Thus, an expression based on the selected User or Team in the Owner field needs to be written.

Mapping the owner field of opportunity with the Owner field of Contact:

We created a Power Automate which will get triggered on the update of the Contact entity record as shown below.

set Owner field dynamically using Power Automate CDS Connector

1- Then we have added Create action to Create Opportunity entity record as shown below using CDS(Current Environment).

 

set Owner field dynamically using Power Automate CDS Connector

2- To set the owner field, we need to add the below expression in the Owner field mapping as shown below.

Expression: if(equals(triggerOutputs()?[‘body/_ownerid_value@Microsoft.Dynamics.CRM.lookuplogicalname’],’systemuser’),concat(‘systemusers(‘, triggerOutputs()?[‘body/_ownerid_value’],’)’),concat(‘teams(‘, triggerOutputs()?[‘body/_ownerid_value’],’)’))

In the above expression, we are checking the Owner field type i.e. User or Team in equal() function using “_ownerid_value@Microsoft.Dynamics.CRM.lookuplogicalname.

The “Microsoft.Dynamics.CRM.lookuplogicalname” returns the logical name of the User or Team entity.

We need to concat “EntitySetName” and “Guid” of the record i.e. systemusers(<guid>) or teams(<guid>).

set Owner field dynamically using Power Automate CDS Connector

Conclusion

Using the above solution, we can set the Owner field dynamically using Power Automate CDS Connector (Current Environment).

Microsoft Power Platform

2 thoughts on “How to set Owner field dynamically using Power Automate CDS Connector (Current Environment)

  1. Priyanka Thakur

    I have a similar requirement in which I have update Contact Owner details and the owner value should be taken from the owner of Current Logged in Users. Can you help me with the same.

    1. Inogic

      To get the logged-in user details, you can run your MS Flow under “Triggering User” as shown below.

      Triggering-User

      So you can get the logged-in user id using “RunAsSystemUserId” as shown in the below screenshot. Using this id you can retrieve the user entity record and can update the Contact owner.

      Triggering-User

      Hope this helps.

      Thanks!

Comments are closed.