Introduction
In our last blog, we saw How to set or map null value in Lookup Field using Power Automate CDS Connector. In this blog, we will explore How to set the Owner field dynamically using Power Automate.
Scenario: On the Contact entity, there is 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 but to set the Owner field is quite tricky. We need to take some extra efforts, that is, we need to add additional expression while mapping the owner field since owner can be User Or Team. So, we need to write an expression based on the selected User Or Team in the Owner field.
You can see below how we are mapping owner field of opportunity with Owner field of Contact:
We created a Power Automate which will get triggered on the update of the Contact entity record as shown below.
1- Then we have added Create action to Create Opportunity entity record as shown below using CDS(Current Environment).
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>).
Conclusion
Using the above solution we can Set the Owner field dynamically using Power Automate CDS Connector (Current Environment).
*This post is locked for comments