Hi team, I have created a flow to grab an attachment from an email, rename it to add the date on the end, and save to a SharePoint folder. The flow is working, but the file name ends up with additional characters either side of the original attachment name, i.e. [_Agent State Details Report_]_20221122.csv
While the additional characters aren't inhibiting any other processes, I'd like to understand why it's happening.
The rename steps and expressions are as follows:
1. Initialize variable: Name - Rename Attachment, Type - String
2. Get Attachment Name: first(split(variables('RenameAttachment'), '.'))
3. Get Attachment Extension: last(split(variables('RenameAttachment'), '.'))
4. New Attachment Name: concat(outputs('Get_Attachment_Name'), '_', formatDateTime(utcNow(), 'yyyyMMdd'), '.', outputs('Get_Attachment_Extension'))
Solved! Go to Solution.
Your loop is ok - if you only have a single attachment then it would only loop once and set the Attachment Name. I've just retrieved the first attachment by wrapping it in a first expression which avoids the loop.
I tried with your exact expressions, and it comes out fine for me (including the loop) so no idea where those brackets are coming from.
Have you investigated the flow output?
Could you please elaborate, is the output not the renamed file?
Hi @vww , I believe @SudeepGhatakNZ meant to confirm if we checked the output of the step 2. Get Attachment Name: first(split(variables('RenameAttachment'), '.')) in the flow. We suspect [ _ are part of the variable RenameAttachment in flow already and are not added by the flow. Please check the output of flow and confirm.
It's hard to tell without knowing how you initially set your RenameAttachment variable.
One thing I noticed is that to get the name you split on period then take the first item. If you have one or more periods in the actual file name, then this will only return the name up to the first period - not necessarily the full name up to the extension.
Below is how I would get the reformatted name.
attachmentName is set to the first Attachment Name using the following expression:
first(triggerOutputs()?['body/attachments'])?['name']
Then, get the last index of "." which should be the period that splits the name and the extension.
lastIndexOf(variables('attachmentName'), '.')
And finally, concatenate the name and date using the following expression.
concat(slice(variables('attachmentName'), 0, outputs('Index')), '_', formatDateTime(utcNow(), 'yyyyMMdd'), slice(variables('attachmentName'), outputs('Index')))
Hi @grantjenkins thanks for providing some extra information. My steps look different to yours - looks like I have an extra "Apply to each" step which might be what's catching me up?
Here's the Initialize variable and Apply to each steps expanded, am I overcomplicating things?
Your loop is ok - if you only have a single attachment then it would only loop once and set the Attachment Name. I've just retrieved the first attachment by wrapping it in a first expression which avoids the loop.
I tried with your exact expressions, and it comes out fine for me (including the loop) so no idea where those brackets are coming from.
User | Count |
---|---|
92 | |
44 | |
21 | |
19 | |
17 |
User | Count |
---|---|
144 | |
51 | |
42 | |
40 | |
31 |