Power Automate: Copy and paste image field in D365
In this article I am going to discuss how you can copy the data inside an image field from one record to the image field of another record. This could come in handy in different ways but what I am trying to accomplish here is to show related ‘hobby’ data on a contact record in Dynamics 365. In the example I am using for this article, I want to show the contact’s hobbies directly on the form and I want to show the image of these hobbies in the view as well, BUT the image is actually stored in another record so I need to copy it from one record and paste it into the record that I am showing on the contact record. Below is an example of what I am trying to do inside the application. I will explain how I accomplished this in this article.
Obviously you don’t have to use custom tables for this functionality to work. You should also be able to use this with existing tables. For example you could use the products and opportunity products tables in Dynamics 365. You would have the image populated on the records in the product table, and copy the image to opportunity products. Another scenario is available in Dynamics 365 Field Service, where technicians are consuming work order products which are also linked to the product table in Dynamics 365. I hope this helps imagining other areas in the application where this functionality can be used.
I created two different tables to be able to accomplish this. The first table is a super simple table which only stores the names and images of different hobby’s. I named the table ‘Hobby'(plural ‘Hobbies’). Besides a name field the ‘Hobby’ table also has an image field. I added a second table which is called ‘Contact Hobby’ (plural ‘Contact Hobbies’). This table has a lookup field to both the contact table and the hobby table I mentioned earlier, making this table a manual many to many relationship between the contact and hobby table. I am going to use power automate to create some logic so that when a new ‘Contact Hobby’ record is created in Dynamics 365, the image in the hobby record (which was selected in the lookup field on the contact hobby record) will be copied from the hobby record. I can then show the contact hobby records on the contact table using a ‘list’ view configuration, which allows for the image to be shown in the grid. (For more details on what this means take a look at this article. The below image should give you a good idea of how the tables are connected in Dynamics 365.
Keep in mind that the Power Automate flow that I’m building during this article will not update existing customer hobby records in Dynamics 365 if the image in the hobby record changes. This flow will only copy the image from the hobby record to the image field of the contact hobby record when the contact hobby record is created. If you wanted to update all Contact Hobby records when the image on the hobby changes, you’ll need to create additional logic. Now let’s take a look at the Power Automate flow!
Create the Power Automate Flow
This Power Automate flow is actually a lot simpler than you might expect! Since we want to update the image when a new record is created for the Contact Hobby table in Dataverse, my trigger is going to be ‘When a row is added, modified or deleted’. In the trigger I will set the change type to ‘Added’ and ofcourse the table name is ‘Contact Hobbies’. I don’t have to expand the advanced options, since I am not going to touch any of those options.
My second step in the flow is where I look for the record that was selected in the ‘Hobby’ lookup field in the newly created Contact Hobby table. I need this so that I can find the image of the ‘Hobby’ record which I need to copy over to the newly created ‘Contact Hobby’ record. My next step is called ‘Get a row by ID’. The table that I am looking for is ‘Hobbies’ and I am going to use Dynamic content to get the row id of the hobby record that was selected in the hobby lookup field of the contact hobbies table. Enter your mouse in the ‘Row ID’ field and start typing the word hobby. Under ‘When a row is added, modified and deleted’ you’ll notice several options for hobby. You click on ‘Hobby (Value)’ to enter the dynamic value into the ‘Row ID’ field.
I am not going to enter any information in the advanced options section of this step as it’s not needed. We have identified the hobby record through this step, and now we’re going to update the ‘Contact Hobby’ record with the same image as in the ‘Hobby’ record. Click on ‘Next Step’ and select Dataverse again. The step you are looking for is called ‘Update a row’. I select ‘Contact Hobbies’ as the table (because this is the table that holds the record we are going to update with the image from the ‘Hobby’ record.) I expanded the advanced options and search for the ‘image’ table.
I click my mouse in the image field in the step and type ‘Image’ in the dynamic content search box. You’ll notice two options to choose from, and here is where you need to think about what you’re doing. Since I need the image from the ‘Hobby’ record, (which we found in the ‘Get a row by id step’) I click on the ‘image’ option below the ‘Get a row by id step’.
I hope you found this article informative! Be sure to check in again next week for a new article or subscribe here to never miss another post!
Comments are Closed