The Organization hierarchy in Office 365 is based on the Manager attribute of users, and can be shown in Delve for example. But the Manager attribute is not synced to Dynamics 365 when users are enabled.
We can get the manager of a user by calling the Get manager (V2) action of the Office 365 Users connector in Flow. Since the Manager field of the User entity in Dynamics 365 is a lookup (to the User entity) we need to get the userid of the manager.
Here is the overview of the flow:
First we get all active users and for each user we get their details and get their manager.
We check if the manager is not empty, and get the user record filtered on the user name of the manager.
Then we get the details of the manager’s user record, if available (I didn’t build in this check yet).
Finally we update the user record with the userid of the manager in case they’re not equal.
And here are the (test) results in Dynamics 365:
The Organization hierarchy is now available in Dynamics 365 as well.
Disclaimer: when the manager is not part of the business unit hierarchy then the flow will presumably fail, so be sure to administer the business unit hierarchy in Dynamics 365 in case of organizational changes that have impact on the security structure.