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 / Rename a Google E-mail...
Power Automate
Answered

Rename a Google E-mail Attachment and Save it to Google Drive

(1) ShareShare
ReportReport
Posted on by 71

I have a flow that is checking an e-mail and saving the attachment (always a PDF) to Google Drive. I would like to rename that file on the save, but having trouble renaming the file based if another Compose (DocumentType) has a certain Word, etc. This is what I have come up with, but I have something missing because it's not renaming the file but it does add the other Compose and Date/Time Stamp.

 

Here is the expression:

concat(
if(equals(item()?['{DocumentTypeVar}'], 'Configuration Pages'), 'CONF',
if(equals(item()?['{DocumentTypeVar}'], 'Delivery and Acceptance'), 'DA',
if(equals(item()?['{DocumentTypeVar}'], 'Receivables'), 'REC',
if(equals(item()?['{DocumentTypeVar}'], 'Picking and Packing Lists'), 'PICPAK', replace(item()?['Name'], '.pdf', '')
)
)
)
),
'-',
outputs('SerialNumberVar'),
'-',
formatDateTime(utcNow(), 'MMddyyyy'),
'.pdf'
)

Categories:
I have the same question (0)
  • Verified answer
    abm abm Profile Picture
    32,865 Most Valuable Professional on at

    Hi @2C4C3C9127 

     

    You meant by the IF conditions are not evaluating at all?

     

    if(equals(item()?['{DocumentTypeVar}'], 'Configuration Pages'), 'CONF',
    if(equals(item()?['{DocumentTypeVar}'], 'Delivery and Acceptance'), 'DA',
    if(equals(item()?['{DocumentTypeVar}'], 'Receivables'), 'REC',
    if(equals(item()?['{DocumentTypeVar}'], 'Picking and Packing Lists'), 'PICPAK', replace(item()?['Name'], '.pdf', '')
    )
    )
    )
    )

     

    Only the  'SerialNumberVar' and MMddyyyy is working. 

     

    The evaluating texts (eg:'Configuration Pages') under the IF condition is case sensitive so make sure its exactly the same for all the texts.

     

    Thanks

  • abm abm Profile Picture
    32,865 Most Valuable Professional on at

    Hi @2C4C3C9127 

     

    Another thing to consider is if its not the exact word then you should use 'contains' instead of 'equal'.

     

    Thanks

  • 2C4C3C9127 Profile Picture
    71 on at

    Thanks for the feedback and I think you are correct about changing it from Equal to Contains. Since I do think there are some line breaks that could cause me an issue.

     

    So I changed it from equals to contains and I'm getting this error: InvalidTemplate. Unable to process template language expressions in action 'Create_file' inputs at line '0' and column '0': 'The template language function 'contains' expects its first argument 'collection' to be a dictionary (object), an array or a string. The provided value is of type 'Null'.'.

     

    The value of DocumentTypeVar is:

    " Picking\nand Packing Lists"
  • abm abm Profile Picture
    32,865 Most Valuable Professional on at

    Hi @2C4C3C9127 

     

    If you want to remove the \n then before comparing the DocumentTypeVar clean up using replace() expression and use the separator as \n. This will give you Picking and Packaging Lists.

     

    Thanks

  • 2C4C3C9127 Profile Picture
    71 on at

    I would guess you mean this expression: replace(outputs('DocumentTypeVar'),'\n','')

     

    I have read that something like this would not work?

  • abm abm Profile Picture
    32,865 Most Valuable Professional on at

    Yes, Did you tried?

  • abm abm Profile Picture
    32,865 Most Valuable Professional on at

    This blog might be helpful.

     

    How to replace new line ('\n') in a Power Automate expression (tomriha.com)

  • Verified answer
    2C4C3C9127 Profile Picture
    71 on at

    Yes, that now works perfectly. I'm still having an issue renaming the attachment from Gmail.

     

    I switched back to:

    concat(
     if(equals(item()?['{DocumentTypeCleanVar}'], 'Configuration Pages'), 'CONF', 
     if(equals(item()?['{DocumentTypeCleanVar}'], 'Delivery and Acceptance'), 'DA',
     if(equals(item()?['{DocumentTypeCleanVar}'], 'Receivables'), 'REC',
     if(equals(item()?['{DocumentTypeCleanVar}'], 'Picking and Packing Lists'), 'PICPAK', replace(item()?['Name'], '.pdf', '')
     )
     )
     )
     ),
     '-',
     formatDateTime(utcNow(), 'MMddyyyy'),
     '.pdf'
    )

     

    Does it have to the with the replace Name - should it be something different?

  • abm abm Profile Picture
    32,865 Most Valuable Professional on at

    Hi @2C4C3C9127 

     

    I noticed that you got curly brackets around your properties

     

    item()?['{DocumentTypeCleanVar}

     

    Change to

     

    item()?['DocumentTypeCleanVar']

     

    Do the similar for all other properties.

  • 2C4C3C9127 Profile Picture
    71 on at

    Updated and tested, still will not rename the attachment.

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 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard