How to Handle Multiple Scenarios? Using Switch Activity?

Hi team,
I have a scenario that I need help from you -
Here is the scenario I have for my current process.
Query from DB table
image

Using Run Query UiPath Studio

This portion of my process depends on the availability of data in the datatable. I query a sql table that is expected to have only two distinct values (2 and 4). And 2 and 4 are Business Units having errors.
Let me explain what I mean by that.

  • When we find only one distinct number let’s say 2, the process will continue with the other Business Unit that has no error (business unit 4). However, there should be an email send out stating that Business Unit 2 has error, please fix it.
  • The same way, when we find only one distinct number let’s say 4 this time around, the process will continue with the other Business Unit that has no error (business unit 2) while sending out email stating that Business Unit 4 has error, please fix it.
  • The third scenario is both Business Unit 2 and 4 being distinct values, meaning both the Business units having errors - in such a case we send out email stating that Business unit 2 and 4 have errors, this time there is no next step, the process stops here.
    Is there anyone who can give me an idea on how to design/ handle this logic?
    Please let me know if you need more clarification about my ask.

Thanks a lot,
Sisay

@Sisay_Dinku,

It’s quiet hard to understand the use case. May be try elaborating by a flowchart or something?

Thanks,
Ashok :slight_smile:

Hi @ashokkarale

Thank you for looking into this
It is going to look like the following -
FYI - the data table has max of 2 rows - my process can handle if this record is just either 2 or 4. However, if the max number of records (2 records,) 2 and 4 the process should stop. It cannot continue to the next step - in such a case for each row in data table does not help - there should be a way we can tell that when the DT has 2 and 4 values send email and stop the process
TestScenario.zip (74.8 KB)
So, I am still trying to figure how I can convert values in DT to list and then if the value of the list is just one and equal to 2, if the value of the list is just one and equal to 4, if the value of the list 2 and 4.
While trying to go through the attached workflow, please try to refer the prior post.
Unfortunately, I cannot share actual data and flow
Thanks!

There are multiple ways to control execution flow - If, Else If, Switch, Flowchart.

It sounds like you have multiple possible outcomes:

  • One record that’s a 2
  • One record that’s a 4
  • Two records

This is where you’d use an Else If.

Hi @postwick
Thank you for looking into this.
Let say - I am using IF condition, can you help me how to write the expression in the condition?

  • In the first condition the data table having distinct value “2”, Not counts. It is a value in a row.
  • In the second condition the data table having distinct value “4”, Not counts. It is a value in a row.
  • In the third condition the data table having distinct two distinct values “2” and “4”, Not counts. they are values the two rows.

My process expects max of two records (“2”,“4” values) - depending on the presence of each or both values different decisions are made.

Hi @Yoichi, @ppr and team,

Can anyone look into this the above?
Please let me know if you’d need more clarification.

Thanks for your help!
Sisay

Hi,

If my understanding is correct, How about the following?

dt_forBU2and4.AsEnumerable.Sum(Function(r) CInt(r("ColumnName")))

Note: The above is assumed that there are 2, 1 or 0 rows in the datatable and the row uniquely has value “2” or “4”.

Regards,

1 Like

That is a smart and elegant solution. Great analysis of the logic.

1 Like

Hi @Yoichi,

I think you got the design right that the dt_forBU2and4 has either no data or distinct # 2 (value) or distinct # 4 (value) or distinct # 2 and 4 (values). Depending on the value of the rows equal to the above (# 2, # 4, # 2 and # 4), different actions (decisions) are taken. However, your query (dt_forBU2and4.AsEnumerable.Sum(Function(r) CInt(r(“ColumnName”)))) looks like it does the summation - forgive me if I got it wrong.

I was trying to use IF condition for each of the three scenarios

  • Scenario 1 - IF BU2: dt_forBU2and4.AsEnumerable().Any(Function(row) row(“ColumnName”).ToString() = “2”)
  • Scenario 2 - IF BU4: dt_forBU2and4.AsEnumerable().Any(Function(row) row(“ColumnName”).ToString() = “4”)
  • Scenario 3 - IF BU2 and BU4 : dt_forBU2and4.AsEnumerable().Any(Function(row) row(“ColumnName”).ToString() = “2”) AndAlso dt_forBU2and4.AsEnumerable().Any(Function(row) row(“ColumnName”).ToString() = “4”)

The problem with above queries (3 scenarios) is, for example, IF data for “2” and “4” are present, Scenario 1 and Scenario 2 get executed - when both “2” and “4” are present - I want only to be executed by Scenario 3.
Scenario 1 is expected to be executed only when there is one record in the data table (dt_forBU2and4) which is “2”, and Scenario 2 is expected to be executed only when there is one record in the data table (dt_forBU2and4) which is “4”

I hope this explanation makes it clear now. Again, please let me know if you’d need any info.

Thanks a lot!
Sisay

Hi,

Your understanding is correct. If there are just single “2” and single “4” in the datatable, summation will always be “6”.

The problem with above queries (3 scenarios) is, for example, IF data for “2” and “4” are present, Scenario 1 and Scenario 2 get executed - when both “2” and “4” are present - I want only to be executed by Scenario 3.
Scenario 1 is expected to be executed only when there is one record in the data table (dt_forBU2and4) which is “2”, and Scenario 2 is expected to be executed only when there is one record in the data table (dt_forBU2and4) which is “4”

IF you want to use IF activity, can you try to use “All” as the following?

  • Scenario 1 - IF BU2: dt_forBU2and4.AsEnumerable().All(Function(row) row(“ColumnName”).ToString() = “2”)
  • Scenario 2 - IF BU4: dt_forBU2and4.AsEnumerable().All(Function(row) row(“ColumnName”).ToString() = “4”)
  • Scenario 3 - IF BU2 and BU4 : dt_forBU2and4.AsEnumerable().Any(Function(row) row(“ColumnName”).ToString() = “2”) AndAlso dt_forBU2and4.AsEnumerable().Any(Function(row) row(“ColumnName”).ToString() = “4”)

Regards,

Hi @Yoichi,

This is the best!!
Thank you so much! I can confirm that it is working as I expected.

Best regards,
Sisay

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