I'm building a flow to save Outlook attachments to a Sharepoint library, but I also need to rename the file based on sender's email address and date. For example, if I receive a PDF attachment from bob@testcompany.com on February 2nd of 2024, I need to name the saved file 'testcompany_2_2_2024.pdf'
I've added 2 compose steps to my flow to get the domain name, but can't figure out the regex to remove the domain suffix (.com, .net, etc) from the composed string.
Here's what my steps look like so far:
1. Initialize Variables
2. Compose Sender and set Sender variable
3. Compose DomainName and set DomainName variable
4. Compose "cleaned" Domain Name (URL suffix removed) and set CleanDomain variable
5. Check that attachment is a PDF, then save it to Sharepoint with a filename based on the CleanedDomain and Time/Date of the email
My questions are:
1) Is there a better way to get the domain name minus the suffix?
2) What's the best way to reformat the date/time to meet my needs?
Hi @SescoDev,
You can use a couple of splits for this. First split on the '@' and only use the second item of the returned split array. After that you can split again on the '.' character. In that case you can use the first item of that second array.
Below is an example expression
concat(first(split(last(split(triggerOutputs()?['body/from'], '@')), '.')), '_',
formatdatetime(triggerOutputs()?['body/receivedDateTime'], 'dd_MM_yyyy'))
@SescoDev another way of getting substring you can check in this post https://powerusers.microsoft.com/t5/General-Power-Automate/How-to-get-string-before-a-character-appearing-multiple-times-in/td-p/843654
to format date time you can use formatDateTime() expression https://learn.microsoft.com/en-us/troubleshoot/power-platform/power-automate/how-to-customize-or-format-date-and-time-values-in-flow
WarrenBelz
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional