cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TCS123
New Member

Trying to create flow to delete items older than 30 days from a Sharepoint library

Hello, I'm trying to create a flow to delete all items older than 30 days from a Sharepoint library.

 

It seems that several other people have asked about this in the past, and in those posts the suggestion was to get file properties, and then use a condition to determine whether the file is older than 30 days as follows:

 

@greater(utcNow('yyyy-MM-dd'), formatDateTime(adddays(item()?['Created'],30),'yyyy-MM-dd'))

 

But unfortunately you can't enter that anymore because they've removed the advanced editor for conditions, and there's no way of putting that in as a function into the basic editor. It seems it needs to be split into two separate functions.

 

So I've tried to split it up in the basic condition editor as follows:

 

left side:

formatDateTime(utcNow(),'yyyy-MM-dd')

 

greater than, right side:

addDays(item()?['Value'], 29,'yyyy-MM-dd')

 

But when I do that I get the following error when trying to test the flow:

Unable to process template language expressions for action 'Condition' at line '1' and column '11862': 'The template language function 'addDays' expects its first parameter to be a string that contains the time. The provided value is of type 'Null'.

 

Thank you to anyone who can help.

1 ACCEPTED SOLUTION

Accepted Solutions
gazzo1967
Impactful Individual
Impactful Individual

@TCS123 
Ok i have had a go at this and it works but for an unexplained reason it works but says there is an error  so if someone else can explain it that would be great

ok here we go

Add you trigger  in your case Recurrence then add the action Sharepoint 'List Folder' (i used manual to test)

 

gazzo1967_0-1614519554084.png

Set List folder to address of sharepoint  and the folder you want to work with

 

the add an 'Apply to Each' the output is 'body' from the List Folder' action

gazzo1967_1-1614519681812.png

 

Then add your 'Condition'

your condition statement should be  'LastModified' this is so you can ensure any files that might still be in use is not deleted and on the right side  add the following formula

addDays(utcNow(),-29)

 

gazzo1967_2-1614519883531.png

on the Yes side of the condition add your delete file
Use your site address and the File identifier is 'ID'

As i said this works but throws up an error after running which i cant explain but says it could be temporary

When you test this i used the 'recycle' function a few times

Also on you folder view in Sharepoint is suggest you show the 'Modified' column so you can check that it is only targeting the older files

Hope that helps 
Gary
PS if this answers the question please mark as complete so others can find it 🙂

View solution in original post

14 REPLIES 14
gazzo1967
Impactful Individual
Impactful Individual

Hi @TCS123 
You can still add your expression in the condition here are the directions from @Pstork1 
Gary

TCS123
New Member

Thanks @gazzo1967 , but I don't really understand. Would you be able to tell me how I could do that in the context of my original line: @greater(utcNow('yyyy-MM-dd'), formatDateTime(adddays(item()?['Created'],30),'yyyy-MM-dd'))

 

Also in that post you linked they said in their case to make it equal to 0. Would that be the same in this example?

 

Many thanks

 

gazzo1967
Impactful Individual
Impactful Individual

@TCS123 
What is your trigger?
gary

TCS123
New Member

Please see the picture below, thanks.

 

Delete items older than 30 days flow.PNG

gazzo1967
Impactful Individual
Impactful Individual

@TCS123 
In your condition
leftside
select Dynamic Content
Get files 'Created'

 

Rightside
Select expression and add

 

addDays(utcNow(),-30)

 

This should remove any files created 30 days or older 
Your condition should look like this

 

Capture.PNG

 Remove the second Apply to each

just put Delete file
select you site

and file identifier is ID

Gary
PS it his answers the question please accept the answer so others can too 🙂

Thank you it does now accept that expression as you've written it, but unfortunately upon testing the flow, every result of the expression returns as false, even though I know there are loads of files in there older than 30 days.

 

Capture.PNG

gazzo1967
Impactful Individual
Impactful Individual

@TCS123 

In the condition change the middle value to either Greater than equal to 
or less than cant remember which
gary

TCS123
New Member

Thanks, using less than or equal to is does now run, but now with another problem. When a result returns as true, it won't delete it, and I think that's because for example it assigns a value to the file e.g 59. But then it gives an error saying there's no such file as 59. So I think I'm going wrong somewhere else with the ID.

 

Capture2.PNG

 

 

TCS123
New Member

Just to confirm the current settings:

 

Capture3.PNG

gazzo1967
Impactful Individual
Impactful Individual

@TCS123 
the delete  file Identifier is definitely ID

Also the Condition Created is from Get file Properties?

gazzo1967
Impactful Individual
Impactful Individual

Unfortunately i cant help anymore right now as it is late friday night in the UK and i am about to have food and alcohol so wont be back until Monday at the earliest
Sorry

TCS123
New Member

Yes to both of those, the file identifier is ID and the condition is from get file properties.

 

Thank you for your help with this, much appreciated!

gazzo1967
Impactful Individual
Impactful Individual

@TCS123 
Ok i have had a go at this and it works but for an unexplained reason it works but says there is an error  so if someone else can explain it that would be great

ok here we go

Add you trigger  in your case Recurrence then add the action Sharepoint 'List Folder' (i used manual to test)

 

gazzo1967_0-1614519554084.png

Set List folder to address of sharepoint  and the folder you want to work with

 

the add an 'Apply to Each' the output is 'body' from the List Folder' action

gazzo1967_1-1614519681812.png

 

Then add your 'Condition'

your condition statement should be  'LastModified' this is so you can ensure any files that might still be in use is not deleted and on the right side  add the following formula

addDays(utcNow(),-29)

 

gazzo1967_2-1614519883531.png

on the Yes side of the condition add your delete file
Use your site address and the File identifier is 'ID'

As i said this works but throws up an error after running which i cant explain but says it could be temporary

When you test this i used the 'recycle' function a few times

Also on you folder view in Sharepoint is suggest you show the 'Modified' column so you can check that it is only targeting the older files

Hope that helps 
Gary
PS if this answers the question please mark as complete so others can find it 🙂

View solution in original post

gazzo1967
Impactful Individual
Impactful Individual

@TCS123 
Does this work for you?
Gary
PS if this answers the question please mark as complete so others can find it 🙂

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Users online (36,936)