I’ve demoed this Flow during my session ‘Automate your Dynamics 365 admin tasks with Flow!’ at Dynamics 365 Saturday Belgium in Brussels last Saturday.
This Flow will set the Site field for Users based on the City field, that is synced from Azure AD.
Here is the overview of the Flow:
First I get the list of Site records that is stripped down to an array with only the Name and SiteId in the next action step.
Then I get the list of active Users and for each User record I check whether the City field is not empty.
Next I filter the Select Sites array on the Name equal to the City. Then I set the String variable to the SiteId from the filtered result, with the expression: body(‘Filter_array’)[‘SiteId’]. If a SiteId is available then it will go through the Succeeded scope, but if no SiteId is found then the action will fail and the flow will continue in the Failed scope.
In the Succeeded scope, the selected SiteId is compared with the Site value of the User record to check if they are equal or not. If not, the User record will be updated with the SiteId.
In the Failed scope, the missing Site is created and its SiteId is used to update the User record.
That’s it. Let the Flow run and the Site field will be set for the active Users, based on their City field.
Here is the download link for the flow: D365Get&SetSiteofUsers
P.S. The Sites entity is part of the legacy service scheduling that will be cut-off if the new service scheduling is installed in your organization.