Execution bot based on day

Hello friends,
@rkelchuri, @Ninett_Panfir, @Rammohan91, @balupad14, @Florent_Salendres, @vvaidya, @Palaniyappan, @ClaytonM, @vvaidya,

I have this situation.
The bot being developed has to be launched every working day in the morning.
If it is launched on Monday it has to process the input files relative to FRIDAY,SATURDAY and SUNDAY.
How is it possible to get the day of the bot execution, in case it is monday process not only one file but three files?
Thank you,
Cami

2 Likes

This should give you the day of the current run,

string today = System.DateTime.Now.DayOfWeek.ToString();

Thanks,
Rammohan B.

1 Like

@CamiCat
Building off of @Rammohan91’s answer:

If you just need the date and not any time information then you can use the Today function instead of Now. For example, today = DateTime.Today.DayOfWeek will assign a numerical value to today. 1 for Monday, 2 for Tuesday, etc.

Then you can use an If activity with the condition today=1 to check whether it’s Monday. If it is then DateTime.Today.AddDays(-1), DateTime.Today.AddDays(-2), and DateTime.Today.AddDays(-3) will retrieve the dates for Sunday, Saturday, and Friday, respectively.

2 Likes

It depends on what the bot is doing.
Ideally, you want to develop your process to pick up any previous day that was missed, regardless of when it runs. If it fails to run Monday, then Tuesday should pick up the Monday file too, for example.

So, if you are waiting on a specific file for each day, you can simply just add a condition to see if the File exists already, like File.Exists(filepath)
Or, if you are performing a search on a web portal, then search every day, and if the file exists, then check if the file exists similarly.

I think many of the processes I make, I set a daysBack parameter (usually 5-7 days), so it processes a weeks work of items, and as it is processing, it skips the ones that were already completed.
For example, you can use a loop such as
For each day In Enumerable.Range(0, 1+daysBack).Reverse.Select(Function(d) Today.AddDays(-1*d))
which basically creates a list of days within a range.

Regards.

1 Like

Thank you so much @ClaytonM.
Can you please share a workflow of how to do the part
For example, you can use a loop such as
For each day In Enumerable.Range(0, 1+daysBack).Reverse.Select(Function(d) Today.AddDays(-1*d))
which basically creates a list of days within a range.?
Thank you,
Cami