How to auto assign records in Dynamics CRM?

The story behind

In companies with different departments there always has a need records to be redirect (or to use the technical term assign ) to a certain people based on some criteria. Whether this is a support team where a new case is assigned to sub-team (such as: Technical Support, Customer Support, Sales Support, etc.), or perhaps a Sales team based on lead creation so they can handle the potential clients. In any way most of the time this is a manual work and there will be either a team leader doing the assignment, or a some kind of queue manager to distribute the work load.

There are some solutions in the marketplace allowing to auto assign records, based on some criterias, but they all are payed (on a monthly and sometimes user bases as well), which can be quite exepensive.

I've decided to share with you a method for auto record assignment using Power Automate. Aswe all know Power Automate is super powerfull, and allows to do an amazing automations. Power automate is also very flexible and allows customization (HTML, CSS, JSON, etc.)

Here's how it's done

  • First thing is to start with a action when a record in Dynamics CRM is created. This can be Case, Lead, Opportunity or anything else that you want to automate the assignment process. I will use Lead in my example.


  • Then we need to get the the team and its members that we are going to assgined the new leads to. Now, this is a bit difficult as you actually don't need the team table, as this will return the team (Sales for example) but not its members, and actually need the members of Sales team, but how and where we are going to take this information from?

If we go to the CRM web API https://<your organization.crm4.dynamics.com/api/data/v9.2/ and search for team, at somepoint in the resukts you will find the following table teammembership. This is actually a middle table between users and teams tables as the relationship between these two is 1:N (one to many, one team can have many users), but also one user can be part of many teams. So this is why there middle entity is required to store all information about all users and all teams in one place.


Here we have the userid and the teamid, so we are going to use this table in Power Automate.


  • So we will manually add teammemberships in tablename, and we will filter by teamid. In this way we are getting only members from certain team (Sales in this case).


  • Next step is to Initialize variable which will actually get the total number of users in the above filtered team from teammemberships table. We will use the following formula: lenght(body('Get_team_members')?['value'])


  • Then we will initialize another variable, but this time we are asking to randomly pick a number from the previous step. We will use the following formula: rand(1,variables('numberOfMembers'))

For example: We have total ot 15 users in the Sales team, the step will pick a random number from 1 to 15.


  • After that we will combine the two variables along with the userid, so that way we will know what user stays behing each number. We will use the following formula: body('Get_team_members')?['value']?[variables('randomNumber')]?['systemuserid']

For example if the syste picks number 7 we need to know who is the user behing this number.


  • One we have the entire formula ready, we need to come back to the intially crated new Lead and update the Owner filed with the Compose steps's output.

Don't forget also to point the type of owner that you are adding (systemusers or team).


That actually everything, we now have automation record assignment process. Hope this will help you with managing your CRM records.

20 views0 comments

Recent Posts

See All