How to set variable base on time condition?

Dear Experts

I have a request as below:

If current date 8:15:00 a.m.<=now<= current date 8:45:00 a.m., then set variable to “1st Trigger”;
If current date 12:15:00 p.m.<=now<= current date 8:45:00 p.m., then set variable to “2nd Trigger”;
If current date 16:30:00 p.m.<=now<= current date 16:55:00 p.m., then set variable to “3rd Trigger”;

How to use VB to show above condition?
And I want to use a general variable [Like “Trigger”] which contains these 3 triggers for next move,
like:
If Trigger=“1st Trigger”, then…
If Trigger=“2nd Trigger”, then…
If Trigger=“3rd Trigger”, then…

Thank you for your kind advise in advance

Regards

Hi @yangyq10

Try this

currentTime = DateTime.Now

If currentTime.TimeOfDay >= New TimeSpan(8, 15, 0) AndAlso currentTime.TimeOfDay <= New TimeSpan(8, 45, 0) Then
    Trigger = "1st Trigger"
ElseIf currentTime.TimeOfDay >= New TimeSpan(12, 15, 0) AndAlso currentTime.TimeOfDay <= New TimeSpan(20, 45, 0) Then
    Trigger = "2nd Trigger"
ElseIf currentTime.TimeOfDay >= New TimeSpan(16, 30, 0) AndAlso currentTime.TimeOfDay <= New TimeSpan(16, 55, 0) Then
    Trigger = "3rd Trigger"
End If

Cheers!!

@lrtetala

Thanks for the quick reply
May I know if I should put them in [assign]?
Or where should I put these VB coding in UiPath?

Hi @yangyq10

currentTime = DateTime.Now

If 
 currentTime.TimeOfDay >= New TimeSpan(8, 15, 0) AndAlso currentTime.TimeOfDay <= New TimeSpan(8, 45, 0) 
Then
    Trigger = "1st Trigger"
ElseIf 
   currentTime.TimeOfDay >= New TimeSpan(12, 15, 0) AndAlso currentTime.TimeOfDay <= New TimeSpan(20, 45, 0) 
Then
    Trigger = "2nd Trigger"
ElseIf 
   currentTime.TimeOfDay >= New TimeSpan(16, 30, 0) AndAlso currentTime.TimeOfDay <= New TimeSpan(16, 55, 0) 
Then
    Trigger = "3rd Trigger"
End If

Check the below flow

Variable Type

Regards

@yangyq10

You need to use this in Assign and Else If activity

Sequence17.xaml (14.0 KB)

Regards,

@yangyq10

FYI, There is another approach

Dim currentTime As DateTime = DateTime.Now
Dim Trigger As String = ""

If currentTime.TimeOfDay >= New TimeSpan(8, 15, 0) AndAlso currentTime.TimeOfDay <= New TimeSpan(8, 45, 0) Then
    Trigger = "1st Trigger"
ElseIf currentTime.TimeOfDay >= New TimeSpan(12, 15, 0) AndAlso currentTime.TimeOfDay <= New TimeSpan(20, 45, 0) Then
    Trigger = "2nd Trigger"
ElseIf currentTime.TimeOfDay >= New TimeSpan(16, 30, 0) AndAlso currentTime.TimeOfDay <= New TimeSpan(16, 55, 0) Then
    Trigger = "3rd Trigger"
Else
	Trigger = "No Trigger"
End If

' Set the out argument for Trigger
out_Trigger = Trigger

Regards,

@lrtetala

Thank you for the solution. I am testing now

I have another small question relative to time

Take today as an example:

If trigger=“1st Trigger”, I should input “15.05.2024” to “16.05.2024” in below SAP column;
If trigger=“2ndTrigger” or “3rd Trigger”, I should input “16.05.2024” to “16.05.2024” in below SAP column

Do you know if any time VB coding can make it happen?

Thank you again for your patience

@Parvathy Thank you for the kind advise. I am testing now. :nerd_face:

1 Like

@yangyq10

Can you try the below

Dim currentTime As DateTime = DateTime.Now
Dim Trigger As String = ""
Dim StartDate As String = ""
Dim EndDate As String = ""
Dim today As DateTime = DateTime.Today

If currentTime.TimeOfDay >= New TimeSpan(8, 15, 0) AndAlso currentTime.TimeOfDay <= New TimeSpan(8, 45, 0) Then
    Trigger = "1st Trigger"
    StartDate = today.ToString("dd.MM.yyyy")
    EndDate = today.AddDays(1).ToString("dd.MM.yyyy")
ElseIf currentTime.TimeOfDay >= New TimeSpan(12, 15, 0) AndAlso currentTime.TimeOfDay <= New TimeSpan(20, 45, 0) Then
    Trigger = "2nd Trigger"
    StartDate = today.ToString("dd.MM.yyyy")
    EndDate = today.ToString("dd.MM.yyyy")
ElseIf currentTime.TimeOfDay >= New TimeSpan(16, 30, 0) AndAlso currentTime.TimeOfDay <= New TimeSpan(16, 55, 0) Then
    Trigger = "3rd Trigger"
    StartDate = today.ToString("dd.MM.yyyy")
    EndDate = today.ToString("dd.MM.yyyy")
End If

' Set the out arguments for Trigger, StartDate, and EndDate
out_Trigger = Trigger
out_StartDate = StartDate
out_EndDate = EndDate

Regards,

I might not read between the lines correctly here, but if by 1st trigger, 2nd trigger etc you mean which orchestrator trigger started the job, there is an easier way then messing around with needless code. (low-code platform right?)

Add an argument to your main.xaml. Just make it a simple string called ‘s_TriggerNumber’ for example.

Now, once this package is deployed and linked to a process, you can add the value for this argument in the orchestrator. In this case add it to your trigger, and setit there.
Now you might want to create 3 separate triggers, one for each case, and match the argument accordingly.

Your robot will then have runtime access to the ‘trigger #’ without reverting to scripting.

@lrtetala Sorry for the late response. I am runing debug this afternoon with your detailed solution. It should be working now. Thank you for the guidance. By the way, may I know how you can screenshot a long UiPath sequence? Usually I have to screenshot 2-3 times when I have a long process to show. :joy:

@Parvathy Thank you for the guidance. Its very clear :smiley:

Let me try if this way can work. Thank you~

@yangyq10

Right click on your main sequence ->Export as Image ->Save Image to File

Regards,

@lrtetala Thanks Bro, you save my day :laughing:

1 Like

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