I have a flow that separates the file name after an underscore. The first 7 digits are the part number, after the first underscore comes the color number and after the second underscore comes the format. Using the split function with split(variables('String'),'_')[0] I split the name of the document with split(variables('String'),'_')[1] split(variables('String'),'_')[2] and transfer the value from the "Format" field to the "Status" field of the Sharepoint document library. This works perfectly for filenames that are 1017277_31390_7 15 digits long.
But now I want to transfer a value to the Status field also for file names 1021114_10332 which have only one underscore and are 13 digits long, in this case the status should have the value "99". It would be perfect if the condition can be checked that only documents with the extension .png and .jpg are processed.
Translated with www.DeepL.com/Translator (free version)
Hello @TomTT ,
to run the flow only for .png and .jpg files you can use a trigger condition - check if the file name ends with the .png or .jpg string and run the flow only if true.
@or(endswith(triggerOutputs()?['body/{FilenameWithExtension}'], '.png'),endswith(triggerOutputs()?['body/{FilenameWithExtension}'], '.jpg'))
For the file name you can adjust just the 3rd expression. Instead of automatically taking the 3rd part of the split
split(variables('String'),'_')[2]
you can combine it with the if(...) expression to check how many parts the string has. If it has 3 pieces, it contains also the 3rd part. If it's less than 3 pieces then there's no 3rd part and use the value 99.
if(equals(length(split(variables('String'),'_')),3),split(variables('String'),'_')[2],'99')
Michael E. Gernaey
497
Super User 2025 Season 1
David_MA
436
Super User 2025 Season 1
Riyaz_riz11
244
Super User 2025 Season 1