Calculate risk using impacyt and urgency in change request

rameshmalla
Tera Contributor

HI  i am trying to set value of risk based on impact and urgency tried using onchange client script on both fields but its not working 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || isTemplate) {
        return;
    }

    var impact = g_form.getValue('impact');
    var urgency = g_form.getValue('urgency');


    if (!impact || !urgency) {
 
        return;
    }

    var risk = '';

    if (impact === '1') {
        risk = '1 - High';
    } else if (impact === '2') {
        if (urgency === '1') {
            risk = '1 - High';
        } else {
            risk = '2 - Medium';
        }
    } else if (impact === '3') {
        if (urgency === '1') {
            risk = '1 - High';
        } else if (urgency === '2') {
            risk = '3 - Low';
        } else {
            risk = '4 - Very Low';
        }
    } else if (impact === '4') {
        if (urgency === '1') {
            risk = '1 - High';
        } else if (urgency === '2') {
            risk = '1 - High';
        } else if (urgency === '3') {
            risk = '3 - Low';
        } else {
            risk = '4 - Very Low';
        }
    }

    g_form.setValue('risk', risk);
}
 
i think i am setting the value of risk i need to set label of that how to do that?
4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@rameshmalla 

you should set the choice value and not choice label for that field.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Roshnee Dash
Tera Guru

Hi @rameshmalla ,

You are setting the label text to the risk variable. please set/assign with the backend value for the variable.

Your feedback makes the community stronger! If you found this helpful, marking it as the correct answer helps others.
Stay awesome,
Roshnee Dash

prerna_sh
Mega Sage

Hi @rameshmalla 
You are setting "choice label" which is incorrect, you should set choice value (backend choice values).
like this:

risk = '1'; // not '1 - High'

 
If my response solves your query, please marked helpful by selecting Accept as Solution and Helpful. Let me know if anything else is required.
Thanks,
Prerna

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @rameshmalla 

Practically, the request you're making is incorrect. In ServiceNow, a risk is used to determine the impact—not the other way around. By reversing this, you're breaking the out-of-the-box (OOTB) risk assessment method. There are OOTB risk conditions that calculate the risk and then set the impact value on the change. Please revisit and validate your requirement, as it currently goes against what the system is designed to do.

 

DrAtulGLNG_0-1753767073686.png

Since it will always be in a loop — you're setting the impact based on risk, and then the risk conditions run and change the impact again — you need to correct your approach here.

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************