Document Retention & Archival using Power Automate
In this post we will see how to set a archival for a document library using "scheduled cloud flow", flow will run every day 12A.M & move the expired files to ArchivalLibrary
In this post we will learn about:
- Scheduled Cloud Flow (Recurrence)
- Actions:
- Get Files(properties only) - get all file properties of library
- Initialized Variable - create new variable in power automate
- Set Variable - Assign values to existing variable
- Apply to each - Looping all items from library/list
- Other Actions:
- Create Item, Get item, Update item, Delete item - For SharePoint List
- Create file, Get files(properties only), Update file, Delete file, Move file, Copy file, Check out file, Check in file, Create sharing link for file or folder, Get file metadata, Get file properties, Get file content using path, Get file Content, Update file properties,etc - For SharePoint Library
- Condition:
- Condition - If & If no based on this we can execute our conditions
- Rename block headings:
- Rename Heading - Rename block headings for better understanding
- Expressions:
- addDays() - will add number of days with given date
- formatedateTime() - will change the string into date formatedateTime
- utcNow() - give current date
- mul() - is a math function will do multiplication
- int() - convert the format into int
- Samples:
- addDays(formatDateTime(variables('CreatedDate'),'MM-dd-yyyy'),mul(int(variables('Retention')),365),'MM-dd-yyyy')
- formatDateTime(variables('ExpirationDate'),'MM-dd-yyyy')
- formatDateTime(utcNow(),'MM-dd-yyyy')
Flow Diagram:
If the document is expired then we will be move to archive folder or delete the document using Power Automate Flow.
Final Flow:
Create 2 SharePoint Libraries:
1.Retention Demo Library
2.Archival Library
Create Same column & Values in both libraries.
Creating Power Automate for Documents Archival:
1.Go to make.powerautomate.com: & select "scheduled cloud flow" set repeat interval as Day & start time
2. Get all files: from Retention Library. New Step> Get Files(Properties Only) > Select Site & Library
3.Initialize new variables(to get meta data from library):
'Retention':
New Step> Initialize variable > Type:string > Rename heading to Retention
'CreatedDate'
'ExpirationDate'
New Step> Initialize variable > Type:string > Rename heading to ExpiraionDate
4. "Apply to Each" looping to get all library files:
4.1 New Step > Apply to Each > select the output from previous step as 'value'
Set Variable 'Retention'=Library 'RetentionYears' Column
Add an Action> Set Variable > Select Variable:Retention > Select Value as Library RetentionYears column > Rename heading
Set Variable 'CreatedDate'=Library CreatedDate Column.
Add an Action> Initialize Variable > Name:CreatedDate > Select Value as Library CreatedDate column > Rename heading
Set Variable ' ExpirationDate'=AddDays(CreatedDate+RetentionYears*365):
Add an Action> Set Variable > Select Variable:ExpirationDate > Select Value as Library RetentionYears column > Rename heading
addDays(formatDateTime(variables('CreatedDate'),'MM-dd-yyyy'),mul(int(variables('Retention')),365),'MM-dd-yyyy')
4.3 Condition(Add Condition to Check Expiration date >= Today):
Add an Action > Condition > Choose Value > "Expiration date >= Today" formatDateTime(variables('ExpirationDate'),'MM-dd-yyyy')>=formatDateTime(utcNow(),'MM-dd-yyyy')
Save Flow & Validate:
Save the Flow
Upload one file in RetentionLibrary & set RetentionYears as 0, so that we can validate with today.
Run & ArchiveFiles: Go to make.powerautomate.com > My flows > RetentionDemoFlow > Run && file will be moved to RetentionLibrary to ArchivalLibary
Run & ArchiveFiles: Go to make.powerautomate.com > My flows > RetentionDemoFlow > Run && file will be moved to RetentionLibrary to ArchivalLibary
Final Flow:
Comments
Post a Comment