Logging Business Exception to a List using LINQ

Is it possible to use LINQ to append a Business Exception to list of Business Exceptions?

The variable which stores these exceptions is of type System.Collection.Generic.IList<UiPath.Core.BusinessRuleException>

As of now I am achieving it using an If Activity as shown below:
IfActivity
Reason I wish to implement LINQ here, is because there are mulitple conditions I wish to check, and this ends up branching off into infinity and the workflow starts resembling the atlas.

Maybe I can start off with something like this:
BusinessException
Any idea how this can be implemented?

Kind Regards,
Ashwin A.K

it looks on a first view that you are searching for a way to handle and evaluate a many conditions and based on this it will add the BException or not, right?

So we would suggest to define all conditions. Maybe you can share this with us. Thanks

1 Like

Hi @ppr ,

Thank you for your response!
Given below is a sample of the code and along with it the business exceptions I will be logging for each condition:


String.IsNullOrEmpty(Str_EventReason.Trim) → New BusinessRuleException(“Employee Status is Empty, please rectify this from your end.”)

Str_EventReason.Trim.Equals(“Rehire”) → New BusinessRuleException(“Employee Status does not coincide with ‘Rehire’, please rectify this from your end.”)

Some are even longer, spanning upto 6-7 If conditions nested inside each other, and I wanted to know if this can be handled, to reduce the branching. At least if the Business Exceptions are logged, then I can focus on the Business Logic development.

If you notice, in one of the ‘Then’ section, I am executing a workflow, so I was wondering if it was possible for the LINQ to return a Bool value that could help me trigger this workflow(maybe I can use an if condition with that Bool value for each workflow, making the interface much easier to navigate, as then it would only increase in length, while remaining relatively constant on the width due to lesser branching).

Thank you for taking the time to look into this, I appreciate it!

Kind Regards
Ashwin A.K

we do following often in processes, maybe this helps. Find the simplified approach (we had some more specifics in our imps, Doing a Black/White evaluation on many Booleans)

  • lets define a new dictionary(Of String, Boolean)
  • add for each check the result to Dictionary e.g. dictValidation(“isEmptyReason”) = String.Null…

ensure that you can evalute All False,True to a final result

then lets Work with following and check e.g for all was true like:
dictValidation.All(Function (kvp) kvp.Value)
lets check if at least 1 true is present:
dictValidation.Any(Function (kvp) kvp.Value)

grafik

with some negations we can test the opposites

Another Technique is to do with result masks (simulating bit masks)
each evaluation is a position in the mask and we start add new tests from left left to right

  • lets define a new dictionary(Of String, Boolean)
  • add for each check the result to Dictionary e.g. dictValidation(“SecondEvaluation”) = True
  • add for each check the result to Dictionary e.g. dictValidation(“First”) = False
    …

Now we use a switch activity and will use the mask for switiching:


grafik

any case we dont want to handle we let switch it to default

1 Like

Hi @ppr ,

This is a really great looking solution and works quite well, but there is one thing I forgot to mention, which is the values are obtained from UI Automation i.e. The Employee Status, Event Reason, Hire Date etc are outputted from Get Text/Get Attribute Activities.

Sorry for not including that in the description, its my mistake.

Also, its after extraction that we evaluate whether to empty the field, populate it, Select another Item(if its a dropdown), or simply log Business Exceptions to our List of Business Exceptions.
Sometimes, Child fields are dynamically populated when we make changes to the parent field(e.g. changing the First Name adds new fields) so I have to evaluate the Parent field at that very instant. This can be handled, its fine.

Its kind of like validating whether the data entered is correct, and if not Log exceptions, or perform other operations.

I don’t know if all of this can be accommodated, because we might be dealing with hundreds or fields, which according to your logic, has to be prepopulated as keys before hand, which then receives its value from the Get Text/Attribute Activities.


PopulatedDataTableofSelectors
ConvertDataTableToDictionary

Is there a way to add each captured UI Element(Which is stored inside a string variable) into a Master Dictionary in one go? Or is there a way to add the values Directly to the Master Dictionary without having to worry about the keys?

I know I’ve really complicated things but you have been really helpful so far, and for that I am deeply grateful.

Kind Regards,
Ashwin A.K