Can someone help me with the date algorithm to achieve the following

Can someone help me with the algorithm to achieve the following . There are two parameters : From Date and To Date . In some case the from date should the last dispatcher run date ( which can be taken by updating the excel or an asset) and the to date as yesterday . But in some cases, there could be future dates as from and to dates. How to build a dynamic algorithm which can handle any dynamic date values

@Ragavi_Rajasekar

What are the conditions where they change…declare two variables for from and two and use if conditions and assign values to them depending on conditions defined in if

Cheers

give an example of what you need

For example 1:
Last run date = 12/10/2023
For Previous dates :
From date = Last run date
To date = Current date -1

Example 2:
Last run date = 12/10/2023
For future dates
From date = current date + something(which is also dynamic)
To date = current date +7 ( which is dynamic )

In this case , how can I build an algorithm to handle both type of conditions

Something with vbscript it is possible.???

Basically I want my two conditions satisfied in two parameters . From and to dates .

So a code with two conditions for each parameters is what I require

Try this out

' Get the last dispatcher run date from Excel or an asset
Dim lastRunDate As Date
lastRunDate = GetLastRunDate()

' Get the current date
Dim currentDate As Date
currentDate = Now()

' Set the from date and to date parameters
Dim fromDate As Date
Dim toDate As Date

' If the from date is a future date, set it to the current date plus the dynamic value
If fromDate > currentDate Then
  fromDate = currentDate + something ' Replace with your dynamic value
End If

' If the to date is a future date, set it to the current date plus 7
If toDate > currentDate Then
  toDate = currentDate + 7 ' Replace with your dynamic value
End If

' Return the from date and to date parameters
Return fromDate, toDate`

Hope this helps

Cheers @Ragavi_Rajasekar

Actually we will not know the dates beforehand .

So what I thought is , we can create a json holding two criteria’s like

Status= previous date
From date : last dispatcher run date
To date : current date -1

Status = future date
From date : current date
To date : current date + add days

If this is a json , I can add this json to the parameter of the process .

I will have a separate input paramter for status .

Based on the that status , in the framework I can replace and use the dates from the json accordingly .

Will this work ? But I need some help in constructing this json

1 Like

@Ragavi_Rajasekar

You can use assets for that and store the value there…

that way only by get and set asset activities you can set and get the values as needed

set the last run value only when successful and get the value at the start of the process

cheers

Yeah that works and it’s a good approach

you can use a JSON to store the dynamic date values for the From Date and To Date parameters. This will allow you to handle both previous and future dates in the same process.

First, define your JSON structure. You can create a JSON string like this

{ "status": "previous date", "fromDate": "last dispatcher run date", "toDate": "current date - 1" }

Now, if the status is “future date,” you can set it like this

{ "status": "future date", "fromDate": "current date", "toDate": "current date + add days" }

In your UiPath process, create input parameters for status, fromDate, and toDate. You can pass the JSON string as the value for the status parameter.

Once you have constructed the JSON, you can pass it to the process as an input parameter. In the process, you can use the status property to determine which date values to use.

Something like this

`' Get the JSON input parameter
Dim json As String
json = InputParameters("json")

' Deserialize the JSON into a C# object
Dim criteria As New Criteria()
criteria = JsonConvert.DeserializeObject(json, criteria.GetType())

' Get the date values from the C# object
Dim fromDate As Date = criteria.FromDate
Dim toDate As Date = criteria.ToDate

' Use the date values in the process`

Hope this clarifies

Cheers @Ragavi_Rajasekar

1 Like

It works ! Thank you !

1 Like

I am unable to pass the json string in the main argument . It give error asking for end of expression required .

Check with the json whether any double quotes or braces are missing
@Ragavi_Rajasekar

Can we pass the value in a json structure to the parameter ? Is it possible ?

Like

{
Xxxxx
{
}
}

In this structure

Yeah
Or
U can pass the actual value from Json directly as parameters

@Ragavi_Rajasekar

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