Hi,
I would like to create flow to rename the file name of the sharepoint list attachment. Please let me know if anyone has any idea on how to do it. I am new to MS-Flow.
For e.g:
User uploads Lotus.jpg and I want to rename it as June-19-5:00PM-Lotus.jpg
Or even June-19-Lotus.jpg is fine.
Thanks in advance.
Kiran
Solved! Go to Solution.
Please have a look at the flow below:
Expression used in the file name is:
concat(formatDateTime(utcNow(),'MMM-dd'),'-',items('Apply_to_each')?['DisplayName'])
Hope this Helps!
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
You must be referencing the wrong identifier in the delete attachment. You have to use the identifier of the get attachments' dynamic value instead of the add attachment ones. Can you please check and confirm this
Please have a look at the flow below:
Expression used in the file name is:
concat(formatDateTime(utcNow(),'MMM-dd'),'-',items('Apply_to_each')?['DisplayName'])
Hope this Helps!
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
@yashag2255 Thank you so much!!! This is the solution I was looking for! it worked as per my requirements. You Rock!!
Thanks,
Kiran
@yashag2255 One concern, when we add another/second attachment then it's deleting the old first one and retaining only the latest one. Any idea how to resolve this? it works only with one attachment.
Can you share more details? I tied this with 2 attachments it was working. (the apply to each loop takes into account all the attachments). Can you share a screenshot of the flow so that I can have a better look at it?
Hi @yashag2255 It works when adding new/first time but does not work while modifing or adding addtional attachments. Screenshot for your refernece. Thanks again for your help.
This is strange! I just tried adding 6 attachments and it worked just fine in my case. Can you share details on how you are attaching the attachments to the item? I also wanted to check if these attachments will be added in a single go (on a particular day) or on multiple days?
Hi @yashag2255 Thanks again for your reply. uploading attachment frequency is not determined, it's random. User may upload while creating the item and come back on same day and upload another attachment or may come back after two days and upload another attachment. So
If the user uploads another attachment after couple of days, then the existing attachment will also get renamed once again (Is there way to check if it's already has date time stamp then skip). Please let me know if you need more info from my end.
I am uploading attachments through normal process of uploading attachments for a sharepoint list item.
Instead of building a logic on checking if the attachment has a valid date as prefix, I have this dirty work around for you (But it works)
See the flow below and replicate
In the array for months:
[ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
In the set variable action:
split(items('Apply_to_each')?['DisplayName'],'-')
In the condition on the right side:
first(variables('attch'))
What the flow does is, it will get the attachment and break the name over '-' (considering that the '-' might exist in a file name) we are checking if the prefix (the month is the first element of the attachment name as per our naming convention) exists in the other array that is an array of months and then perform respective actions.
Hope this Helps!
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
Hi @yashag2255 Thanks for your help and appreciate the patience. I tried the new flow but it's not saving due to variable initailzation for attach variable, I tried giving possible intial values but still getting the following error.
Error message:
"The inputs of workflow run action 'Condition' of type 'If' are not valid. The variable 'attch' must be initialized before it can be used inside action 'Condition'."
That is strange! Can you please put [] this in the Intiialise variable (attach) and try once? Also, can you please check the expression that you put there?
This could also be a caching issue so you might want to save the flow and log out of the current session -> close the browser and start a fresh session.
Please try the above and see if you contiue to get the error.
Ah! I think I found the issue:
It should be the months array instead of the attach array that is on the left side in the condition and it should be first(attach) in the right side.
Hope this Helps!
and this expression
first(variables('attch'))
should be
first(variables('attach'))
as you have named your variable attach.
Really sorry for that @yashag2255 : I did not realize that the variable name is used in the expression! Appreciate your patience. After updating the expression the workflow ran without any error but it's deleting the renamed file instead of the original file 😞
Screenshot of the complete flow.
Part-1
Part-2
You must be referencing the wrong identifier in the delete attachment. You have to use the identifier of the get attachments' dynamic value instead of the add attachment ones. Can you please check and confirm this
@yashag2255 Thank you so much Yash!!! it's working as expected! I appreciate your patience and willingness to help!!! Also, apologize for not following exact instructions and because of that you had to spend extra time to resolve the same.Thank you!
Thanks again!
Kiran
Thank you for this post. It helped me setup a flow to rename the attachments. As I was testing I ran into a use case that i would like to find a solution for.
The use case is this. Attach a file, let the flow run, then add a second attachment, let the flow run again. What happens for me is the 1st attachment gets renamed a second time. It isn't a big deal but it would be nice if the apply to each would be able to skip a file that already has prefix.
The only difference for me in my flow is I use the ID and a hyphen as the prefix.
Here is a screenshot of 3 attachments. the first 2 were first added together and the 3rd on a second edit.
User | Count |
---|---|
87 | |
37 | |
25 | |
13 | |
12 |
User | Count |
---|---|
117 | |
55 | |
36 | |
23 | |
21 |