cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jkb6011
Advocate I
Advocate I

Conditional Expression - If Sharepoint Attachment is of Content Type Image/ PNG, Then

I have a flow that gets attachments from Sharepoint and Populates them into a Word Template. Some of the attachments in the list are PNGs while others are email attachments. I only need to write the images to the Word Template. I've been able to write the images to the Word Template by appending the attachments to an array variable and leveraging the variables function with an index in an expression, like this:

 

variables('AttachmentsVariable')?[0]

 

What I'd like to do now is validate that the attachment is an image/ png file. The logic should be:

 

If the attachment is of content type image/ png, then return the image content, otherwise, return a static white image that is stored in a variable.

 

This is the code I'm trying to leverage to achieve the functionality, but it isn't considered a valid statement:

 

if(equals(variables('AttachmentsVariable')?[0]?[$content-type],"image/png"),variables('AttachmentsVariable')?[0],variables('1x1 Image'))

 

I've seen where validation is done using the Condition task, but I'd like to keep this in the Expressions pane, if possible. Anyone know how to achieve this?

 

@Pstork1 @Rhiassuring @GeorgiosG @abm @Expiscornovus Would appreciate any help I can get!

5 REPLIES 5
abm
Super User
Super User

Hi @jkb6011 

 

I believe your issue is here

 

variables('AttachmentsVariable')?[0]?[$content-type]

 

Could you please post a screenshot of your flow how to storing these in an array?

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials
jkb6011
Advocate I
Advocate I

@abm @GeorgiosG Sure can, thanks for taking a look.

 

jkb6011_0-1651832544601.png

 

 

jkb6011_2-1651832620075.png

 

Let me know if you need any other screen shots

jkb6011
Advocate I
Advocate I

@abm @GeorgiosG

 

I provided the screen shots that were requested. Could you please take a look?

eliotcole
Super User
Super User

Hi, @jkb6011 , this works as a for your issue.

 

Solution - Attachment ID in 'Get file metadata'

For each attachment you can retrieve the mime type image/pdf or image/jpeg by placing the attachment ID in the File Identifier field of the , @jkb6011 .

 

So in an apply to each on the attachments of a list item, you would use:

 

 

 

@{item()?['Id']}

 

 

 

That will bring up the ID of the current item, and retrieve its mime type.

 

Then it's just a matter of using conditional logic on that to decide whether or not to process the item.

OK, so you just need to use the Id for a given attachment to retrieve the metadata for the file. This is done thusly:

yessss file type is begotten - setup.jpg

 

Giving the following results:

yessss file type is begotten.jpg

 

 

eliotcole
Super User
Super User

@jkb6011 I've resolved it, above ... I'm just going to put an amended image in there that somewhat matches yours, but hopefully the logic here is clear.

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (1,285)