User Power Automate to add image to SharePoint image column (guide)

154
0
2 weeks ago
abureaux
MVP Regular Contributor

When I started this little project for someone, I thought it was going to be a lot easier than it ended up being. Since I tried so many different methods and they all didn't work, I'll share with you the one that did.

First, we need a survey to collect images for us. I created this simple survey called "SP_Image_Guide". Pro Tip: SharePoint's image column really only works with a single image, so we want out image question to only allow a single attachment.

abureaux_1-1714156152731.png

Next, we need a SharePoint list. I created a new list called "SP_Image_Guide" and added a single new column: myImage. Pro Tip: When making SP list columns (and anything in SP, really), give it a simple name with no special characters or spaces first. After it has been created, then you can rename it to whatever you want.

abureaux_3-1714156326123.png

The 'myImage' column is Type: Image'.

abureaux_2-1714156282955.png

Now start a new flow (don't forget to turn off "New designer" in the top right). The Trigger will be when our new survey is submitted.

abureaux_4-1714156536097.png

Create a couple String Variables.

abureaux_5-1714156588485.png

Add 'Get attachment from URL'. This can be a little misleading at first. To do this, type 'Esri' > select your appropriate connector (ArcGIS for AGO environments, or ArcGIS Enterprise for Enterprise environments) > then add 'Get attachment from URL'.

abureaux_8-1714156884030.png

abureaux_7-1714156855205.png

Search for 'attachment' in the Dynamic Content, and add your attachment URL.

abureaux_9-1714157024901.png

Even though we are only working with a single Image, all attachments in S123 are created as arrays. As such, Power Automate will automatically put our step into an Apply to Each. That's totally fine! We will be working inside this Apply to Each until I say otherwise.

abureaux_10-1714157103219.png

Next, we need to put that attachment somewhere. I used Create File and saved it in a folder on my SP site. Pro Tip: When adding the Folder Path, don't forget to click on the "Folder" icon for easy navigation.

abureaux_11-1714157166638.png

Dont forget that your file name needs to be unique. I added my attachments name from Survey123, but when in doubt, append utcNow()

abureaux_12-1714157365693.png

abureaux_18-1714157838208.png

Set you two variables. Source is the previous Create File.

abureaux_16-1714157664286.png

Your Apply to Each is now complete. You can minimize it and continue.

abureaux_17-1714157689235.png

Now we add Create Item to create this item in our SharePoint list. And here we can finally see why this is such an annoying operation... there is no Image question! That's okay though.

abureaux_20-1714158181310.png

By this point, we have now saved our image somewhere and created a SharePoint item. Cool. Now, let's merge the two together. Add a 'Send an HTTP request to SharePoint'. Copy what I have below.

Site AddressYour SP Site
MethodPOST
Uri_api/web/lists('*SP List ID*')/items(*Create Item ID*)/validateUpdateListItem()

Headers

(Click the "Switch Headers to text mode" button just to the right of Headers)

{
"Content-Type": "application/json;odata=verbose",
"accept": "application/json;odata=verbose"
}

Body

{"formValues":[{"FieldName":"*SP Image Column Name*","FieldValue":"{\"type\":\"thumbnail\",\"fileName\":\"*variables('imgName')*\",\"fieldName\":\"*SP Image Column Name*\",\"serverUrl\":\"https://*your SP site name*.sharepoint.com\",\"serverRelativeUrl\":\"/sites/*Your SP Site**variables('imgPath')*\"}","HasException":false,"ErrorMessage":null}],"bNewDocumentUpdate":false,"checkInComment":null}

abureaux_0-1714165820392.png

Pro Tip: To get you SP List ID for the Uri, go to your SP list > Click 'Settings' in the top right > Click 'List Settings' > copy the alphanumeric code in the URL bar.

abureaux_21-1714158416672.png

Pro Tip: The body makes more sense when you look at it in the image below. To generate the below image, I copy-pasted the body into VS Studio Code, Find and Replaced (Ctrl+H) all \" with ", and then delete the " (two total) surrounding FieldValue's curly braces. Then right-click anywhere in the window and click Format Document. The above mess is using the \ to escape the ", so it ends up looking worse than it really is.

abureaux_22-1714159065160.png

Pro Tip: You can find the proper column names for your SP List by going to your SP List > Setting > List Settings > Scroll down to the "Columns" section > Click on a column name > look in the URL bar

abureaux_24-1714159684982.png

That's all there is to it! Here is an overview of the full flow.

abureaux_26-1714160118097.png

And here is a test run.

abureaux_23-1714159561294.png

 

0 Kudos
0 Replies