web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Build a flow that will...
Power Automate
Suggested Answer

Build a flow that will change the file name based on the field inside the content

(1) ShareShare
ReportReport
Posted on by 47
Dear all,
 
I'm seeking for your help in building flow that will rename the file name based on the field inside this file. Here is the flow for my current situation:
 
- The file is in pdf type (some will in handwritten and some will be typed) -> I already built an AI Builder that will detect the field column inside (Name, Title, Phone, Email, Position, Working place, State, Date of contract signed) so how can I build a flow that will rename the file with the field I choose - assuming I will take these fields: Name, Title, Working place) and the file name after changed will be: Name_Title_Working place.pdf
 
Thank you so much for reading my post and hope to receive your support for building this flow.
 
Categories:
I have the same question (0)
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at
     
    Below are some steps you can follow for this (the steps are assuming that a file is uploaded to a SharePoint Library)\
     
    Trigger: When a file is created - (Select the appropriate SharePoint Site and Library)
    Get file Content - (Select the appropriate values for site, library and file identifier)
    Process File through the AI Builder Model
    Create File - In this action, you can select a different Library (and a different site too) where you want to store the renamed file. And in this action, for file name, you can use the outputs from the AI builder action and use content from the Get File Content action. 
     
    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!
  • Suggested answer
    Riyaz_riz11 Profile Picture
    3,860 Super User 2025 Season 2 on at
    Hi,
     

    Step-by-Step Flow Implementation

    Step 1: Create the Flow Trigger

    Trigger: "When a file is created (properties only)"


    • Site Address: Select your SharePoint site

    • Library Name: Select the document library containing your PDFs

    • Folder: (Optional) Specify folder if needed

    •  

    Step 2: Get File Content

    Action: "Get file content"


    • Site Address: Use dynamic content from trigger

    • File Identifier: Use "Identifier" from trigger

    •  

    Step 3: AI Builder - Extract Information

    Action: "Extract information from documents"


    • Document: Use "File content" from previous step

    • AI Model: Select your pre-built AI Builder model

    • This will extract: Name, Title, Phone, Email, Position, Working place, State, Date of contract signed

    •  

    Step 4: Initialize Variables for Data Cleaning

    Variable 1: CleanName

    Name: CleanName
    Type: String
    Value: (will be set in next step)

    Variable 2: CleanTitle

    Name: CleanTitle
    Type: String
    Value: (will be set in next step)

    Variable 3: CleanWorkingPlace

    Name: CleanWorkingPlace
    Type: String
    Value: (will be set in next step)

    Step 5: Clean and Format Extracted Data

     

    Action: Set Variable (CleanName)

    Name: CleanName
    Value: replace(replace(replace(replace(replace(first(body('Extract_information_from_documents')?['documents'])?['fields']?['Name']?['values'])?['text'], ' ', '_'), '/', '_'), '\', '_'), ':', '_'), '.', '_')
     

    Action: Set Variable (CleanTitle)

    Name: CleanTitle
    Value: replace(replace(replace(replace(replace(first(body('Extract_information_from_documents')?['documents'])?['fields']?['Title']?['values'])?['text'], ' ', '_'), '/', '_'), '\', '_'), ':', '_'), '.', '_')
     

    Action: Set Variable (CleanWorkingPlace)

    Name: CleanWorkingPlace Value: replace(replace(replace(replace(replace(first(body('Extract_information_from_documents')?['documents'])?['fields']?['Working place']?['values'])?['text'], ' ', '_'), '/', '_'), '\', '_'), ':', '_'), '.', '_')

    Step 6: Create New File Name

    Action: Initialize Variable

    Name: NewFileName
    Type: String
    Value: concat(variables('CleanName'), '_', variables('CleanTitle'), '_', variables('CleanWorkingPlace'), '.pdf')

    Step 7: Handle Empty Fields (Optional but Recommended)

    Action: Condition

    If: and(not(empty(variables('CleanName'))), not(empty(variables('CleanTitle'))), not(empty(variables('CleanWorkingPlace'))))
     

    Yes Branch: Continue with renaming
    No Branch: Handle missing data (see Step 9)

    Step 8: Rename the File

    Action: "Update file properties"


    • Site Address: Same as trigger

    • Library Name: Same as trigger

    • Id: Use "Identifier" from trigger

    • Title: Use variables('NewFileName')

    •  

    Alternative Method (If above doesn't work):
    Action: "Copy file"


    • Current Site Address: Original location

    • Current Library Name: Original library

    • Current File Identifier: From trigger

    • Destination Site Address: Same location

    • Destination Library Name: Same library

    • Destination File Name: variables('NewFileName')

    •  

    Then add:
    Action: "Delete file"


    • Site Address: Original location

    • Library Name: Original library

    • File Identifier: From trigger

    •  

    Step 9: Handle Missing Data (No Branch)

    Action: Compose

    Value: Default_Document_@{formatDateTime(utcNow(), 'yyyyMMdd_HHmmss')}.pdf

    Action: Update file properties


    • Use the composed default name
     
    If I have answered your question, please mark it as the preferred solution ✅ . If you like my response, please give it a Thumbs Up 👍.
    Regards,
    Riyaz
  • FlowInside178 Profile Picture
    47 on at
     
    Thank you for your replies, but I got the trouble with expression is invalid when pasting this expression
    Name: CleanName
    Value: replace(replace(replace(replace(replace(first(body('Extract_information_from_documents')?['documents'])?['fields']?['Name']?['values'])?['text'], ' ', '_'), '/', '_'), '\', '_'), ':', '_'), '.', '_')
     
    So how can I fix this expression? Below is my screenshot of my flow - I use OneDrive because I'm just a new comer so I will access the sharepoint later.
     
     
  • Suggested answer
    Riyaz_riz11 Profile Picture
    3,860 Super User 2025 Season 2 on at
    Hi,
     

    1. Trigger Setup

    Trigger: When a file is created (in a folder)
    ├── Site Address: [Your SharePoint Site]
    ├── Library Name: [Your Document Library]
    ├── Folder: [Target Folder Path] 

    2. Initialize Variables (Top Level)

    Initialize variable: FileName
    ├── Name: FileName
    ├── Type: String
    ├── Value: (leave empty)
    
    Initialize variable: CleanName
    ├── Name: CleanName
    ├── Type: String
    ├── Value: (leave empty)
    
    Initialize variable: CleanTitle
    ├── Name: CleanTitle
    ├── Type: String
    ├── Value: (leave empty)
    
    Initialize variable: CleanWorkplace
    ├── Name: CleanWorkplace
    ├── Type: String
    ├── Value: (leave empty)
    
    Initialize variable: NewFileName
    ├── Name: NewFileName
    ├── Type: String
    ├── Value: (leave empty)

    3. File Processing

      Get file properties
    ├── Site Address: [Your SharePoint Site]
    ├── Library Name: [Your Document Library]
    ├── Id: triggerOutputs()?['body/Id']
    
    Get file content
    ├── Site Address: [Your SharePoint Site]
    ├── Library Name: [Your Document Library]
    ├── Id: triggerOutputs()?['body/Id']

    4. AI Builder - Extract Information

    Extract information from forms
    ├── Form type: [Your Custom AI Builder Model]
    ├── Form: outputs('Get_file_content')?['body'] 

    5. Field Extraction and Cleaning 

    Extract Name Field:

    Compose: Extract Name
    └── Value: 
    @{first(body('Extract_information_from_forms')?['tables'][0]?['rows']?[0]?['cells']?[0]?['text'])}
    
    Set variable: CleanName
    └── Value: 
    @{replace(replace(replace(replace(replace(outputs('Extract_Name'), ' ', '_'), '/', '_'), '\', '_'), ':', '_'), '.', '_')}

    Extract Title Field: 

    Compose: Extract Title
    └── Value: 
    @{first(body('Extract_information_from_forms')?['tables'][0]?['rows']?[1]?['cells']?[0]?['text'])}
    
    Set variable: CleanTitle
    └── Value: 
    @{replace(replace(replace(replace(replace(outputs('Extract_Title'), ' ', '_'), '/', '_'), '\', '_'), ':', '_'), '.', '_')}

    Extract Working Place Field: 

    Compose: Extract Working Place
    └── Value: 
    @{first(body('Extract_information_from_forms')?['tables'][0]?['rows']?[2]?['cells']?[0]?['text'])}
    
    Set variable: CleanWorkplace
    └── Value: 
    @{replace(replace(replace(replace(replace(outputs('Extract_Working_Place'), ' ', '_'), '/', '_'), '\', '_'), ':', '_'), '.', '_')}

    6. Generate New File Name

    Set variable: NewFileName
    └── Value: 
    @{concat(variables('CleanName'), '_', variables('CleanTitle'), '_', variables('CleanWorkplace'), '.pdf')}

    7. Rename File

    Update file properties
    ├── Site Address: [Your SharePoint Site]
    ├── Library Name: [Your Document Library]
    ├── Id: triggerOutputs()?['body/Id']
    ├── Title: @{variables('NewFileName')}
    ├── Name: @{variables('NewFileName')}
     
    If I have answered your question, please mark it as the preferred solution ✅ . If you like my response, please give it a Thumbs Up 👍.
    Regards,
    Riyaz

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard