This post is inspired by following Microsoft Tech Community conversation:
Using Power Automate, Outlook attachments are being saved to SharePoint. Attachments need to be renamed based on extracted text from the email subject line. For example: “text1 text2 11849850 – text3”
The SPLIT function breaks a string into a table of sub-strings based on a specified delimiter. Using our example from above and specifying a space (“ “) as the delimiter:
The FIRST function returns the first record of a table.
The LAST function returns the last record of a table.
To get “11849850” out of “text1 text2 11849850 – text3” we have to break down the string into its parts and filter out what we don’t need. Within Flow:
- Initialize a variable called varEmailSubject to store the example text
- Remove the hyphen by initializing another variable called varSubject using the following expression:
split(variables('varEmailSubject'), ' - '))
- Remove “text3” using the FIRST function in the varSubject action with the following updated expression:
first(split(variables('varEmailSubject'), ' - '))
- Remove “text1” and “text2” using SPLIT in the varSubject action:
split(first(split(variables('varEmailSubject'), ' - ')), ' ')
- Finally, use LAST in the varSubject action to get the target value:
last(split(first(split(variables('varEmailSubject'), ' - ')), ' '))
The final formula looks complicated but once broken down into its smaller parts its more manageable.
Thanks for stopping by.