We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Need help with Client script on the incident table for Impact and Urgency fields ?

Pooja Khatri
Tera Contributor

Hello All ,

I have a requirement where in my Incident form there are two drop down fields - Impact and Urgency
in Impact the options are : 1 - widespread , 2 - significant , 3 - moderate , 4 - contained , 5 - isolated


and in Urgency we have option : High , Medium High , Normal

 

so for all the users other than the manager role , if the user selects and option of 1 - widespread in IMPACT it should hide the option for High in URGENCY and
if they select High in URGENCY it should hide the option of 1-widespread in IMPACT


and it should throw and alert message saying 'Only Managers are allowed to select values'

 

How can I implement this functionality ?

19 REPLIES 19

Hi @Pooja Khatri share your script here let me correct it

Regards
Harish

Hi @Harish KM - This is the script :

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var userRole = g_user.hasRole('major_incident_manager');
    var getImpact = newValue; // selected impact value
    if (!userRole && getImpact == 1) //impact value 1 for high
    {
        g_form.removeOption('urgency', 1);
    }
else {
g_form.addOption('urgency', 1);
}
}

Hi @Pooja Khatri here is the correct script

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

    var userRole = g_user.hasRole('major_incident_manager');
    alert(userRole);
    var getImpact = newValue; // selected impact value
    if (!userRole && getImpact == 1) //impact value 1 for high
    {
        alert("not Incident Manager");
        g_form.removeOption('urgency', 1);
    } else {
        g_form.addOption('urgency', 1,'1 - High',0); // added fieldname,choice value, sequence
    }
}
Regards
Harish

Hi @Harish KM - this is not working out instead of showing the field values again it is adding one more field to the label which is not needed ? any other approach can I implement it that it would work successfully ?

Hi @Pooja Khatri can you share the script?

Regards
Harish