How to Name File Sequentially and Did Not Lose the Counter State

I am still new in this UiPath world and it’s been years since the last time I code intensively, I need help in this one.

So here is the case:
In SAP, after I automate some of the tcode execution, at the end of the steps I need to save file in local (spreadsheet) using SAP save local feature.

I need to give the file name with this format:
" <number 01-99>"

Usually when I code manually in other language, I can do it, in pseudocode, by giving curdate+number counter loop, but since this is attended robot that runs every 15 mins, will the counter lose it’s state? Let say currently it save file as “16-02-2021 01”. How can I make sure that the next time the robot runs the file name will be “16-02-2021 02” instead of returning to 01?

And finally, is there any sample? As you can see, when the date change, I want the counter to reset back to 01 again, any idea how to do that?

Thanks. Regards

I can’t find the edit post button on mobile phone, but there is something left out due to html

"I need to give the file name with this format: curdate(DD-MM-YYYY) (number 01-99)

And the End of the Workflow write the counter value to text file. So next time when you open the file it will be 01. Read this value and add this to counter.

For the File Name: You can try. “XYZ_” + Now.tostring(DD-MM-YYYY) + " number " + counter.tostring + " -99.xlsx"

if you want with brackets feel free to add it at the right place in the above code.

1 Like

Goddamn I didn’t even think of writing it to a text file. I will test it again. But before that, how do I make sure that the next day the counter reset to one? Sorry this might sound dumb and I am not on my laptop right now, but right now I imagine storing the number in .txt file and it will work fine for that day, but the next day I need the counter to go back to zero. If it reads the .txt file, it’s not zero right?

@Liu_Nado - Then I think, along with the counter check, you have to check for the date too. If the date is equal to today’s date, you keep incrementing the counter.

So the next day, when you start the processing, date check will fail then you have to reset the counter to 0 or 1 and start over again.

1 Like

If you are already reading the files in the save directory, get the file with the max counter for today’s date then add 1.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.