How to use Switch with datetime format

Hi team!

I got a question about coding … How do you manage to use Switch statement with datetime format ?
I know how to do it in C# and VB .net but dont manage to use our native activity, let me show you an example :

  • I have a Switch configured with TypeArgument = System.Datetime

  • When I try to switch a date (2 days ago in the example) it’s ok but, the problem comes when I try to add cases

Capture

  • Just after adding this, I get an error

Capture

I mean, I can use an invoke code but I’m courious about how to solve this in UiPath

Thanks in advance !

Hug

Hi @jmedinacarbonell

Did u change the argument type in switch as datetime?

Hi, yes, as said, I changed it to System.datetime

Did it worked perfectly as of now

You mean, it worked for you ? Can you share an example plz ?

the cases only accept hardcoded values such as this
image

so you need to think of other ways when using switch such as looking at the day / day of week

image

1 Like

Hi @jmedinacarbonell ,
what is your intention with the switch? I think if you use “today.adddays(-2)” as expression, you will always have the case “today.adddays(-2)”. Or do you want to switch in case of how many days is a given date away from today? so the expression would be something like “today - yourdatevariable” and the case would be 0, 1, >3 etc.
Regards
Moritz

Hi Jack, tanks

So, you conclude that in the switch activity from UiPath we just can manage typeArguments like String or int32 right ?

Hi, thanks for your comment,

As said, its just an example so, yes, your solution is changing the variable to compare with an int32 in order to know the distance in time from today, thats right

My question comes exactly in that point:

  • Today, when I can, I use switch in this way, I “transform” the variable to analyze in order to have cases in String or int32

  • There are some cases where I coulnd’t do it, of course, not the case I exposed but close. In those cases, I’m used to place an invoke code, where I can Switch any kind of typeArgument (as used in C#, vb .net, Python, Javascript …)

And here is the point, Im wondering if you guys managed to use Switch activity with other typeArguments, like Datetime, not int32 or String

yes, thats my understanding, only hardcoded values.

Hi @jmedinacarbonell,
I didn’t manage to use a swith with other types of arguments. I 've found a solution to do some more complicated expressions by using nested Ifs. It was in a flow switch, but I think it will work in a switch as well:

But I think, that is not what you are looking for :slight_smile:

Regards
Moritz

I’m just changing this topic to Studio feedback just to let it open as feature request untill UiPath team find it interesting to resize the activity with a wider typeAgument list

Thanks anyway for your quick feedback @mm1904 , @jack.chan , @NIVED_NAMBIAR !!

Hug

We are looking into allowing expressions instead of just static values for Switch cases, maybe they’ll be available in 21.10.