Sync Office 365 User Photos to CRM Users with Flow

Background

I got a requirement that the client needs user profile photos in Office 365 to be synced to CRM Users. It is Dynamics 365 CE Online, and users don’t change profile photo often. There is no OOB way to achieve it so I need to develop custom synchronization.

The workflow

First of all, I think the synchronization is nothing fancy, it is just a workflow which has a trigger and multiple actions. So I just need to design the flow, then I can think of how to implement it.

  • Trigger: Because it is not required to sync at real-time when users update photos, I want to manually or schedulely trigger the workflow.
  • Find all CRM users who has no photo or needs photo update.
  • Get profile photos for those CRM users from Office 365
  • Update CRM users entity image with the photos

Implementation in MS Flow

I decided to use Flow to implement the workflow because Flow is very powerful and easy to use especially in integrating between online systems/services, in our case Dynamics CRM and Office 365. Another advantage is that I don’t have to write a single line of code, so there won’t be any bug (hopefully 🤞) and I won’t have to worry about deployment or hosting the workflow somewhere. The Flow will look like this

Flow to update CRM User profile photos

I think the Flow is self-explanatory. I just note down some things you will need to focus:

  • Here I choose a manually trigger for easy testing, I can switch to a Recurrence trigger to run the Flow schedulely.
  • In “Get CRM Users” step, you’ll only want to filter users that have no image or need photo update. Here I created a custom Yes/No field in User entity as a flag, and filter the records based on the flag.
  • In “Apply to each” loop, I wrap everything inside a “Scope – Try” because if some users has no Office 365 profile or photo, the Flow will throw error. The “Scope” will swallow and ignore the error. You may want to log the error somehow in your case.
  • With “Get user photo (V2)” step, you need to select the “V2” one, it will get the profile photo correctly.
  • In “Update a record (Preview)”, you need to select the “Preview” one, so it can update the Entity Image field correctly. And in the Entity Image field just set it to the result of the “Get user photo (V2)” step.

Now we can run the Flow and see the CRM Users updated with photos.

That’s it! Hope it helps!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s