I have a flow that saves email attachments to sharepoint library. some attachments comes with an extra text... for example - Sales_Data_21-03-1982KNR.PDF - sometimes they come without it. is there a way I can ensure that to save such files without KNR in filename? basically I would like to replace "KNR" with "no space" so that its omitted... thanks
Solved! Go to Solution.
If you want to retain the original case, you could do multiple replace actions like this:
replace(replace(replace(items('Apply_to_each')?['Name'], 'knr', ''), 'KNR', ''), 'Knr', '')
This will leave the original filename untouched but remove "knr", "KNR" and "Knr". I have an article on my blog for proper case:
Use an expression like this:
replace(outputs('Filename'), 'KNR', '')
You will need to replace the outputs('Filename') with whatever dynamic content contains your filename.
Hi @Paulie78
the attachment name - when I copy to notepad shows this - @{items('Apply_to_each')?['Name']}
but when I use the code you suggested, I get "expression is invalid" error...
I used below...
replace(items('Apply_to_each')?['Name'], 'knr',")
could you help me correct it please?
replace(items('Apply_to_each')?['Name'], 'KNR',")
Hi @Paulie78 I got it to work with the following.... but it passes files with knr (lower case) - is there a way to fix that?
replace(items('Apply_to_each')?['Name'], 'KNR', '')
replace(toLower(items('Apply_to_each')?['Name'], 'knr', ''))
it fails with following...
InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '1' and column '3175': 'The template language function 'toLower' expects one parameter: the string to convert to lower casing. The function was invoked with '3' parameters. Please see https://aka.ms/logicexpressions#toLower for usage details.'.
is there a way to modify your original code to include both "KNR" & "knr" ?
Sorry, put the brackets in the wrong place and didn't test it, try this:
replace(toLower(items('Apply_to_each')?['Name']), 'knr', '')
replace(toLower(items('Apply_to_each'))?['Name'], 'knr', '')
or
toLower(replace(items('Apply_to_each')?['Name'], 'knr', ''))
Thank you @Paulie78 and @VictorIvanidze
as the resultant filename becomes fully lowercase - I used toUpper() in the file creation time to change it....
I wish there was a "toProper" function to capitalize only first letters of the file name words (eg: Sales Data 21-02-2012)
but the main objective is accomplished! - Thanks a ton!
If you want to retain the original case, you could do multiple replace actions like this:
replace(replace(replace(items('Apply_to_each')?['Name'], 'knr', ''), 'KNR', ''), 'Knr', '')
This will leave the original filename untouched but remove "knr", "KNR" and "Knr". I have an article on my blog for proper case:
Could you mark @Paulie78 's answer as a solution?
Learn to digitize and optimize business processes and connect all your applications to share data in real time.
Read the latest about new experiences and capabilities in the Power Automate product blog.
User | Count |
---|---|
26 | |
26 | |
25 | |
21 | |
17 |
User | Count |
---|---|
53 | |
46 | |
33 | |
33 | |
30 |