133
Views
8
Comments
Solved
Use expression (if/else) from database in assign
Application Type
Reactive

Hello everyone,

I have a server-side "assign" action that checks (analyzes) a database record for several conditions and assigns some value when one of the conditions is met. For example:

if(GetData.List.Current.Data.Attribute1="ABC" or (GetData.List.Current.Data.Attribute1="CBA" and Length(GetData.List.Current.Data.Attribute2)=3,"200",/next If condition/....

The problem is that I have now 50+ conditions that need to be checked and all of them are hard-coded in this server-side action. Since my data is quite 'vivid' I have to add/change those conditions regularly, which requires deploying a new version of application every time.

Is there a way to save my 50+ conditions in a database record and use the record in the analyze/assign action? 

It would allow me the change the if-conditions at any time just by updating the db-record without publishing new app version, and then running my "analyze" action on click. Obviously this would mean that correctness of my conditions will not be checked by the ServiceStudio, but I can live with that.

Looking forward to your ideas.

Cheers,

2023-05-30 10-05-13
Lourenço Matalonga
Solution

Hello @Dimitri Kobzar ,

something like that is not possible. You will have to find the best approach from the above and comprise a little bit. 

Best regards,

Lourenco Matalonga

UserImage.jpg
Dmytro Kobzar

Hi Lourenco. Although this is bad news for me, nevertheless thank you for confirming it.

2023-05-30 10-05-13
Lourenço Matalonga

Hi Dimitri,

yeah i would save those values in a static entity called conditions and then in the if statement use the specific condition. This way you would only need to change the static entity records and not mess with the if statements.

Hope this helps,

Lourenco Matalonga

2026-02-26 06-29-24
Rahul
 
MVP

Hi,

You can use site property for an update by the service center at any time so in this way not have any hard coded values and it will be configurable.


Hope this will help you.

2023-05-30 10-05-13
Lourenço Matalonga

Hi Rahul,

i don't think having 50 site properties in this case is appropriate.

If it was 3-5 that would be ok but more than that i think it really does not make sense and it not really a best practice.

Best regards,

Lourenco Matalonga

2023-06-07 04-47-12
Ayush Tyagi

Hello ,

You can use your conditions dynamically in your server-side action and store them in a database record, so yes. With this method, you can modify the circumstances without launching a new version of the application. Here are the steps for how to do it:

1. Create a new database table: Set up a new database Entity to store your conditions. Define columns(Attributes) in the table to represent the different values and conditions that you need to evaluate.

2. Populate the Entity: Insert the 50+ conditions into the database Entity. Each row would represent a separate condition and contain the necessary data for evaluation, such as the attribute values, comparison operators, and expected outcomes(As per your task).

3. Fetch conditions in your server-side action: In your server-side "analyze" action, add logic to fetch the conditions from the database Entity. You can use a database query to fetch the desired records.

4. Traverse through the conditions: Traverse through the fetched conditions in your server-side action. For each condition, check the attributes and comparison operators dynamically to determine if the condition is met or not.

5. Perform the required actions: Based on the result of each condition, perform the necessary actions or assignments in your server-side action.

By storing the conditions in a database table, you can easily change or add new conditions by updating the records in the table, without requiring a new application deployment. 

I hope this helps you.

cheers.

2021-03-05 13-56-11
Ricardo Pereira
 
MVP

Hi,

In addition to all that had being said, In you place, I separate the different validations in different actions (group validations by some kind of type) and call that actions int the main action. With that you will have code more legible and easy to maintain, since you only will need to mess in a given separate action in case of changes or errors.


Hope this can help you.


Best regards,

Ricardo

UserImage.jpg
Dmytro Kobzar

Thank you guys for quick replies.

If I understand you all correctly, then it would mean that my (static) entity with conditions should have an attribute and a certain value for every attirbute of the data that I check?

So in the example it would mean that instead of doing condition IF(GetData.List.Current.Data.Attribute1="ABC"... I would have GetData.List.Current.Data.Attribute1=GetConditions.List.Current.Condition1.Attribute1... Correct?

If it is so, then it would not make it any easier to maintain the analysis logic. My main issue is not that the condition value needs to change (e.g. ABC needs to be changed to "ACB"), but that the whole logic of the condition needs to change - for example for condition 1 I need to check whether Attribute1 of the data does not just equal ABC anymore, but ends with ABC instead... And I have 46 attributes in the data that I need to check - for some conditions I check only 3 of those, for others I check 10.. And it happens often that for a condition where I checked only 3 attributes yesterday now I need to check one more.

I was looking for a way to save the whole IF statement in an attribute of each condition - regardless whether it consists of one simple 'if A=B' condition or needs to be changed to a complex 'and/or' condtion later... Is something like this possible?

2023-05-30 10-05-13
Lourenço Matalonga
Solution

Hello @Dimitri Kobzar ,

something like that is not possible. You will have to find the best approach from the above and comprise a little bit. 

Best regards,

Lourenco Matalonga

UserImage.jpg
Dmytro Kobzar

Hi Lourenco. Although this is bad news for me, nevertheless thank you for confirming it.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.