# Risk Management - Using "rating" DocFied to calculate... is it possible?

Hi Guys, I’m planning to create some Risk Management forms, due to some regulatory needs I have, and… I don’t want to use Excel anymore.

So, I did a Doctype called “Risk”, and trying to use ‘severity’ and ‘probability’ as criteria, to evaluate risk.

The ‘qualification’ need to be the multiplication of those fields… So, i did, in Client Script (but isn’t working) a formula to calculate it:

``````frappe.ui.form.on("Risk", "cur_frm.severity", function(frm) {
frm.set_value("cur_frm.initial_risk_qualification", (flt(cur_frm.severity) * flt(cur_frm.probability)));
refresh_field("cur_frm.initial_risk_qualification");
});

frappe.ui.form.on("Risk", "cur_frm.probability", function(frm) {
frm.set_value("cur_frm.actual_risk_qualification", (flt(cur_frm.probability) * flt(cur_frm.severity)));
refresh_field("cur_frm.actual_risk_qualification");
});
``````

So, I need to understand 2 thing, if somebody can help me:

1. Is it possible to use those “rating” docfields in this logic? (I saw in the console, and the values are passing normally).
2. The JS is not working. Is it possible to do in Client side? Where am I screwing with?
3. Is it possible to use this logic to populate the ‘risk_qualification_before and after_treatment’? (maybe dividing by 5)?

Thanks!!

Francisco Mesquita

3 Likes

I am not sure if this will help but try
to remove `cur_frm` from your code:

to

``````frappe.ui.form.on("Risk", "severity", function(frm) {
frm.set_value("initial_risk_qualification", (flt(frm.doc.severity) * flt(frm.doc.probability)));
refresh_field("initial_risk_qualification");
});

frappe.ui.form.on("Risk", "probability", function(frm) {
frm.set_value("actual_risk_qualification", (flt(frm.doc.probability) * flt(frm.doc.severity)));
refresh_field("actual_risk_qualification");
});
``````
1 Like

@xickomesquita In believe that you can achieve what you want like this.

``````frappe.ui.form.on('Risk', {
severity: function(frm) {
frm.set_value('initial_risk_qualification', flt(frm.doc.severity) * flt(frm.doc.probability));
frm.refresh_field('initial_risk_qualification');
},
probability: function(frm) {
frm.set_value('actual_risk_qualification', flt(frm.doc.probability) * flt(frm.doc.severity));
frm.refresh_field('actual_risk_qualification');
}
});
``````
1 Like

Understood the sintax now. (probabily there is a better way to write it, but…) Thanks!!

``````frappe.ui.form.on('Risk', {
probability: function(frm) {
frm.set_value('initial_risk_qualification', flt(frm.doc.severity) * flt(frm.doc.probability));
frm.set_value('risk_qualification_before_treatment', (flt(frm.doc.severity) * flt(frm.doc.probability)) / 5);
frm.refresh_field('initial_risk_qualification');
frm.refresh_field('risk_qualification_before_treatment');
},
probability_after_treatment: function(frm) {
frm.set_value('actual_risk_qualification', flt(frm.doc.severity_after_treatment) * flt(frm.doc.probability_after_treatment));
frm.set_value('risk_qualification_after_treatment', (flt(frm.doc.severity_after_treatment) * flt(frm.doc.probability_after_treatment)) / 5);
frm.refresh_field('actual_risk_qualification');
frm.refresh_field('risk_qualification_after_treatment');
},
severity: function(frm) {
frm.set_value('initial_risk_qualification', flt(frm.doc.severity) * flt(frm.doc.probability));
frm.set_value('risk_qualification_before_treatment', (flt(frm.doc.severity) * flt(frm.doc.probability)) / 5);
frm.refresh_field('initial_risk_qualification');
frm.refresh_field('risk_qualification_before_treatment');
},
severity_after_treatment: function(frm) {
frm.set_value('actual_risk_qualification', flt(frm.doc.severity_after_treatment) * flt(frm.doc.probability_after_treatment));
frm.set_value('risk_qualification_after_treatment', (flt(frm.doc.severity_after_treatment) * flt(frm.doc.probability_after_treatment)) / 5);
frm.refresh_field('actual_risk_qualification');
frm.refresh_field('risk_qualification_after_treatment');
}
});
``````