cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
KiranGongani
Level: Powered On

How to rename SharePoint list attachment file name or append the date/time to the file name

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

2 ACCEPTED SOLUTIONS

Accepted Solutions
Dual Super User
Dual Super User

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

Hi @KiranGongani 

 

Please have a look at the flow below:qqas.png

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!

View solution in original post

Dual Super User
Dual Super User

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

Hi @KiranGongani 

 

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

View solution in original post

18 REPLIES 18
Dual Super User
Dual Super User

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

Hi @KiranGongani 

 

Please have a look at the flow below:qqas.png

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!

View solution in original post

KiranGongani
Level: Powered On

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

@yashag2255  Thank you so much!!! This is the solution I was looking for! it worked as per my requirements. You Rock!!

 

Thanks,

Kiran

Dual Super User
Dual Super User

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

Hey @KiranGongani 

 

Glad that it worked!

 

Thanks, 

Yash. 

KiranGongani
Level: Powered On

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

@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.

Dual Super User
Dual Super User

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

@KiranGongani 

 

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?

KiranGongani
Level: Powered On

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

Hi @yashag2255 It works when adding new/first time but does not work while modifing or adding addtional attachments. Screenshot for your refernece. AttachmentRenameFlow.pngThanks again for your help.  

Dual Super User
Dual Super User

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

HI @KiranGongani 

 

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?

KiranGongani
Level: Powered On

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

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.

 

 

 

Dual Super User
Dual Super User

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

Hi @KiranGongani 

 

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 replicatefad1.png

 

fad2.png

 

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!

 

KiranGongani
Level: Powered On

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

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'."AttachmentRenameFlow2.JPG

Dual Super User
Dual Super User

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

Hi @KiranGongani 

 

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. 

 

 

KiranGongani
Level: Powered On

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

Sorry @yashag2255  I tried the below steps but no luck. 

Dual Super User
Dual Super User

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

@KiranGongani 

 

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!

Dual Super User
Dual Super User

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

@KiranGongani 

 

and this expression 

first(variables('attch'))

should be 

first(variables('attach'))

as you have named your variable attach. 

KiranGongani
Level: Powered On

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

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 😞

Attachment-delete-original.JPG

Screenshot of the complete flow.

Flow-1.jpgPart-1

flow-2.jpgPart-2

Dual Super User
Dual Super User

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

Hi @KiranGongani 

 

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

View solution in original post

KiranGongani
Level: Powered On

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

@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-meme-01Thank you!


Thanks again!
Kiran

Dual Super User
Dual Super User

Re: How to rename SharePoint list attachment file name or append the date/time to the file name

@KiranGongani 

 

Glad that it worked! Happy Flowing!

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors (Last 30 Days)
Users online (5,303)