Make a calculation based on field choice value

cicgordy
Tera Guru

Hi all,

Wondering if you can help me with this.

I created a demand risk assessment section/tab and added some fields. Depending of what I chose (Yes/no OR High/medium/low), I want to make a sum of the values I have given to the choices (I have explained the points into the image below), and by clicking the UI action "Demand risk calculation" the sum of all the points should automatically populate in the read only "Risk score" field at bottom, and also populate High/medium/high in the read only  "Risk level" field (if sum is 2 = Low, if sum is 3 to 9 = Medium and if sum is 10+ = High).

 

 

Many Thanks

 

1 ACCEPTED SOLUTION

@cicgordy 

 

Please find the screenshot below:

PrinceArora_0-1683640705733.png

PrinceArora_1-1683640740340.png

 

Syntax is not correct.

 

 

 

View solution in original post

12 REPLIES 12

Prince Arora
Tera Sage
Tera Sage

@cicgordy 

 

As mentioned by you as you already mentioned the backend values as integers

You can simply sum up all the values as mentioned below(Assuming your UI action of client side):

 

var sum = parseInt(g_form.getValue("your_field_name1")) + parseInt(g_form.getValue("your_field_name2")) + parseInt(g_form.getValue("your_field_name3"));



if(sum>10){

g_form.setValue("risk_level","high");

}else if(sum >2 && sum<10){

g_form.setValue("risk_level","medium");

}else{

g_form.setValue("risk_level","low");

}



g_form.setValue("risk_score",sum);

g_form.save();

  

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Hi @Prince Arora , Should this script be a client script or a business rule?? 

Also I only created the UI action, but haven't scripted anything in it as I needed help with that one too, can you please also help with UI action script ?? Thank you 🙂

@cicgordy 

 

This is the script you have to mention in the client side UI action, just mention the script in your UI action and update the backend names according to you fields name and try it.

 

Hi @Prince Arora , I have done as you suggested and correctly updated backend names of fields and choice values, but when I click the UI action something odd happens an all the tabs disappear and system is unable to load the page, so not working.