Power Automation (Flow) send email with Image from Picture Field (Sharepoint list)
The Scenario - When item is created in list B, and list B has the ID for item in list A, go get list A item by id, where there are some details including a Picture field, and send all that via email.
The main thing to remember is that MS did not develop the api needed for the flow to get the picture field, so we cant read nor update it, only via HTTP.
Steps:
- trigger when item created in list B
- parse listItemB_ID field from float to integer
- get item from list A via flow
- get item from list A via HTTP request to SharePoint (*not premium)
- get the Picture field value, it's a JSON
- parse that json
- give a schema for the parser
- where do we find the sample for the schema
- build the Picture url
- send email
1. trigger when item created in list B
2. parse listItemB_ID field from float to integer
the item A id field, although set to be integet, is eventually a float for the flow. we must parse it using the `int` function, using int(triggerOutputs()?['body/CouponID'])
3. get item from list A via flow
This is actially a duplicate, steps 3 and 4, and I could've just get the item via HTTP and parse that response, but I was lazy, and happy to have an example for both.
Also its nice to have Get Item, singular, there used to be only Get Items, plural, and then you needed to extract the item.
4. get item from list A via HTTP request to SharePoint (*not premium)
This step they lately took out from premium, unlike other HTTP requests._api/lists/GetByTitle('CouponsList')/items('@{variables('CouponID')}')
outputs('Send_an_HTTP_request_to_SharePoint')?['body/d/CouponBackGround']
6. parse that json
The JSON parser is great, you must provide a schema. It sounds scary but its not, just take the JSON from last step (run the flow), click on "Generate from sample", paste and "done".7. give a schema for the parser
That's how it looks.8. where do we find the sample for the schema
When you run the flow, that's how it looks, the JSON response, copy paste it as instructed in step 6.9. build the Picture url
The JSON of the image actually contains seperatly the serverUrl (the tenant) and the rel url for the image, so you need to pick them both.
As you can see, once you parse a json result its very easy to use it, and you dont need anymore the "Get Item" step.10. send email
You must use the Image Tag in HTML mode.
Have Fun!
P.S. - at the client's tenant, Get Item failed for the Picture Field... so lucky me I used the HTTP results :)
Comments
Post a Comment