cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Magikmissy
Helper II
Helper II

Add time stamp to file name

Having looked through the community, I think this is a really obvious bit of knowledge which I don't have and which highlights my ignorance!! 🙈

I've created a flow that saves attachments with specific words in the name to OneDrive. I'd like them to save with a unique identifier, eg the date. How do I do that?! 😁

 

scrn.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
edgonzales
Super User II
Super User II

@Magikmissy 

Hi there.  So, there are a few ways to do this...this way uses the least amount of 'functions' and I'll be really detailed so I don't miss covering something you might want:

 

First thing would be to add the step "Current Time".  This will grab the current date/time in a long format like this: 2020-01-16T15:43:22.9817623Z   - Note that this won't be in your local timezone unless you sit right in UTC or GMT.  We can fix the timezone and ugly formatting in the next step.

 

Next, add the step "Convert time zone" and use the output from your 'current time' step as the 'Base time'.  Select UTC as the source time, and then your local timezone as the destination timezone.  If you want to keep everything in UTC (if you're working internationally, as an example), then just set the destination to UTC also.

 

In the format part, you can choose from the list, but none of those will work great as file names, so the best bet will be to go to the bottom of the list an select "Enter custom value" and then type in your own format.  I used yyyyMMdd_hhmm which is the four digit year, followed by the 2 digit month (note the caps), then a 2 digit date, an underscore and then the time.  Here's what it all looks like:

 

20200116b.PNG

 

At the end, I used a "Compose" to store the information, and then you can drop that into the rest of your filename (maybe...depending on where/how you're storing the file).  The output looks like this:     20200116_0743

 

Hope that helps.  Keep us posted.

-Ed-

 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

View solution in original post

25 REPLIES 25
edgonzales
Super User II
Super User II

@Magikmissy 

Hi there.  So, there are a few ways to do this...this way uses the least amount of 'functions' and I'll be really detailed so I don't miss covering something you might want:

 

First thing would be to add the step "Current Time".  This will grab the current date/time in a long format like this: 2020-01-16T15:43:22.9817623Z   - Note that this won't be in your local timezone unless you sit right in UTC or GMT.  We can fix the timezone and ugly formatting in the next step.

 

Next, add the step "Convert time zone" and use the output from your 'current time' step as the 'Base time'.  Select UTC as the source time, and then your local timezone as the destination timezone.  If you want to keep everything in UTC (if you're working internationally, as an example), then just set the destination to UTC also.

 

In the format part, you can choose from the list, but none of those will work great as file names, so the best bet will be to go to the bottom of the list an select "Enter custom value" and then type in your own format.  I used yyyyMMdd_hhmm which is the four digit year, followed by the 2 digit month (note the caps), then a 2 digit date, an underscore and then the time.  Here's what it all looks like:

 

20200116b.PNG

 

At the end, I used a "Compose" to store the information, and then you can drop that into the rest of your filename (maybe...depending on where/how you're storing the file).  The output looks like this:     20200116_0743

 

Hope that helps.  Keep us posted.

-Ed-

 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

View solution in original post

Thank you so much @edgonzales! I'm going to try it now, but just quickly... whereabouts in the process do I insert it?! (Sorry, I really am a newbie!)

Also, I'm English and on GMT so can I skip that step? How does that work?  

😍

You can put this anywhere as long as it is before the step where you're saving the file.  It's independent of pretty much anything.

If you're comfortable with expressions, you can replace everything with a single Compose and this expression: 

formatDateTime(utcNow(),'yyyyMMdd_hhmm')
 
If you're not comfortable with those (yet 😉), then I'd suggest keeping the "Convert time zone" step with the same source and destination, and basically use that step just to get the date format you want.
 
Let us know how that works out.
-Ed-
 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

Great, thanks! (I love the faith you have in me... 'yet'...!!!) How about the UK thing? 

It's a slippery slope and I think we all inevitably will glide down to some degree.  I'm working on a series that will make expressions less scary for 'non-developers' or 'code-averse' folks like myself.  Here's a link to my channel, but it won't launch officially until next month.

 

On the UK thing, that's up to you.  If you're ok with the long format of the date, then you can still the Convert time zone step.  If you want anything different, then I typically use that as an easy way to format the date.  Just leave the source and destination time zones the same, it won't do any math and will just put the date in a format you like.

 

Good luck!

-Ed-

 

 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

You're a star, thank you so much!! 😍

Magikmissy
Helper II
Helper II

I'm sorry @edgonzales, I think I must have done something wrong! It's functioning with no errors but still saves as just the file name with no date. Where have I goofed up? 

 

scrn.jpg

No problem at all.

In your Create File step for One Drive, under file name, you'll want to add the output from your Compose, right?

 

You could also add in a separator like an underscore or something if you want.  So it would look like:

  • Folder path:  /Risk Assessment
  • File Name: <Dynamic Value for Attachments Name>_<Dynamic output from Compose>
  • File Content: <Dynamic Value for Attachments Content>

 

Does that help?

-Ed-

@edgonzales Like this? 

 

scrn.jpg

Perfect.  sort of.  I just thought of something: The filename extension is getting in the way.  So, if the filename is risk assessment.jpg, the thing you and I built will try to name the file risk assessment.jpg20200116_0824

 

we'll have to do some stuff to make it risk assessment 20200116_0824.jpg, but it will actually use the stuff in my one and only video 🙂

 

I'll build something real quick to demonstrate.

@Magikmissy 

Ok, buckle up.  😀

So, this is going to seem like a lot, but I'm going to be super detailed so you get the behind-the-scenes part and can apply it in the future.  There are some expressions, but if you're comfortable with Excel functions, these aren't too different.  I'll try to correlate them as I go.

Once we determine that the filename has "Risk Assessment" in the filename, the first thing we need to do is separate the filename from the extension.  In my example, I'm using "Insurance Risk Assessment.xls" as the filename, so 'xls' would be the extension part.

If you watched my one video 😊 you'll already know that we can use Split() while using the period as a delimiter, but we may want to account for a filename that includes periods in the name, like Insurance.Risk.Assessment.xls, so we only want the last 'element' of the array that's created when we split the filename at the period.  That function looks like this (you would replace  triggerBody()['text'with your attachment filename dynamic value.

 

  • last(split(triggerBody()['text'],'.'))

Drop that into a compose, and that will give us the suffix of the filename, or the 'xls' part.

 

Next, we want to grab the left part of the filename (prefix) up until the last period, or the suffix, to make certain we have the whole thing.  In Excel, we would do this with a version of Left(<cell>,Find(".xls",<cell>)-1).  In Power Automate, it looks like this (I tried to make it pretty):

 

substring(

    triggerBody()['text'],0,

        add(

            indexof(

                triggerBody()['text'],last(

                    split(

                        triggerBody()['text'],'.'

                    )

                )

            )

        ,-1)

)

 

You can copy and paste that into the expression for another compose (rename that one "filename Prefix") and replace all the bold bits with your dynamic attachment filename.  What this is doing, is grabbing a substring of characters starting at the left (position '0') and going until it finds the suffix part, and then backing up one space so it doesn't also grab the final period (that's the Add and -1 part).

 

Finally, back in our Create File step, we drop the dynamic values from our FileName Prefix compose, followed by our date compose (like you did in your version), and then a period, and then the filename suffix compose.  Here's what that looks like:

20200116c.PNG

 I just threw something in the file content part so it wouldn't error, yours would be actual content.  And, all of this is happening in the "Yes" path of your condition.

 

I know it sounds scary, but break it into tiny bits and don't get frustrated when (not 'if') things give you trouble.

 

Keep us posted.

-Ed-

 

 

Sorry @edgonzales, I need help with what triggerBody()['text'should actually be! I just can't figure it out. 😔

@manuelstgomes can you help me at all

@Magikmissy 

No worries at all, sorry for jumping over that.

So, all of these expressions, you would be building/typing in the expressions dialogue box (the same one you use to pick the dynamic values, but the next 'tab' over).

As you're typing your expression, if you want to use a dynamic value as part of the expression, just click back over to the dynamic value 'tab' and select the piece you want to use.  You'll see in the image below, I had to click out of the expression a little so I could see the tab to click on it...that's pretty normal.  Wherever I have triggerBody()['text'], you would click over to the dynamic value for your Attachment Filename.

 

(Also, in my example, I just picked a random step...you wouldn't need to edit this particular step in yours)

 

Once you've completed the expression, click Ok or Update and PA will yell at you if there are any errors in your expression.

 

Let's see if I can get this gif to work:

 

ezgif.com-optimize.gif

 

Hope that helps.

-Ed-

Hooray! I thought you'd left me!!! 😂 Is this right...? scrn.jpg

Didn't leave, just 8 hours behind you 🙂

If it didn't yell at you when you finished building, then we're off to a great start.  It looks good to me so maybe give it a go and see what happens.

 

Keep us posted.

-Ed-

🤣

OK... good news is that it worked. Bad news is...scrn.jpg

Funny.  Ok, so I totally missed this.  You built the expression correctly...but it wasn't in the expression box.  That's why the filename prefix looks like the actual expression and not the intended result.  Think of that as like the = sign when starting a formula in Excel.

 

Check the gif in my previous post and watch how I first click on the field/action I want to work with, then go to the right in the 'pop-up' and select "Expression".  Once there, you can start building the expression.

 

Edit:  I just realized the gif got cut short.  Let me see if I can use the original video...hang on.

 

Keep at it.  We are very close 🙂

I mean... I didn't want to say... but... your gif seems to finish too soon...!!! 😜 It shows you clicking in the box and the pop-up appearing, but then immediately restarts. 

Helpful resources

Announcements
MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (55,851)