User attribute values lost in synchronization > Flow to the rescue: Middle Name

Posted by

The Full Name of the User entity is a composite field that is based on the system setting: Set the full-name format

The Name Format in our case is: First Name Middle Name Last Name, where the Middle Name is used for inserts (tussenvoegsels). The First Name and Last Name are synced from local AD to Azure AD and then to Dynamics 365, but the Middle Name gets the middle finger when it comes to synchronization to Azure AD.
When a new user with a middle name is enabled in Dynamics 365 I have to do an Export to Excel Online, populate the Middle Name field and then choose for the option Save changes to Dynamics 365 that starts an import job. This is something that I would like to automate with the help of Flow.

This is the overview of the flow:
Part 1: First I initialize the variables I need further down in the flow and then get all active users from Dynamics 365 and for each user I check if it’s not an external user (if this is not applicable in your case you could skip this condition).

Part 2: Then I get the user profile and set the length of the First Name, Last Name and Display Name with the expression: length().

Part 3: If the Display Name is longer than First Name + 1 space + Last Name then there must be a Middle Name in between. The expression I use in the condition is:
add(add(variables(‘LengthFirstName’), variables(‘LengthLastName’)), 1)

If so, I calculate the length of the Middle Name with the expression:
sub(variables(‘LengthDisplayName’),add(add(variables(‘LengthFirstName’),variables(‘LengthLastName’)),2))

and get it via the substring expression:
substring(body(‘Get_user_profile_(V2)’)?[‘displayName’],add(variables(‘LengthFirstName’),1),variables(‘LengthMiddleName’))

If the calculated Middle Name is not equal to the Middle Name of the user record, then the user record is updated with this.

I’ve tested this flow in our Dynamics 365 acceptance environment and came to the conclusion that its logic is tackled by a difference in Last Name and Display Name when the maiden name is included in the Display Name but not in the Last Name. So I didn’t implement this flow in our production environment.

Leave a Reply

Your email address will not be published.