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 @Harish KM - Have pinged you on ServiceNow messenger 

Pratiksha2
Mega Sage

Hello @Pooja Khatri ,

1. Please try to use below OnChnage client script if impact changes:

var userRole = g_user.hasRole('itil'); // check manager role here
if (!userRole) {
    var getImpact = g_form.getValue('impact'); // get selected impact value

    if (getImpact == 1) // impact value 1 for widespread
    {
        g_form.removeOption('urgency', '1'); // remove High choice from Urgency
        alert ('Only Managers are allowed to select values');
    }
}

2. Please try below OnChange client script if urgency changes:

var userRole = g_user.hasRole('itil'); // check manager role here
if (!userRole) {
    var getUrgency = g_form.getValue('urgency'); // get selected urgency value

    if (getUrgency == '1') // urgency value '1' for High
    {
        g_form.removeOption('impact', '1'); // remove Widespread choice from Impact
        alert ('Only Managers are allowed to select values');
    }
}

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Pratiksha

 

Hi @Pratiksha2 - I tried with the below script for impact : 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var userRole = g_user.hasRole('manager'); // check manager role here
    if (!userRole) {
        var getImpact = g_form.getValue('impact'); // get selected impact value

        if (getImpact == 1) // impact value 1 for widespread
        {
            g_form.removeOption('urgency', '1'); // remove High choice from Urgency
            alert('Only Managers are allowed to select values');
        }
 
but even after that I am still able to see the option of HIGH in URGENCY , how can I fix it ?
    }
}

Hi @Pratiksha2 there is a error in your script

var userRole = g_user.hasRole('manager'); // check manager role here
if (!userRole) {
var getImpact = g_form.getValue('impact'); // get selected impact value

if (getImpact == 1) // impact value 1 for widespread
{
g_form.removeOption('urgency', 1); // there should be no single codes here, like this '1'
alert('Only Managers are allowed to select values');
}
}
}

Regards
Harish

Hello @Pooja Khatri ,
Please try using below code,

   var userRoles = g_user.getRoles(); 
if (userRoles.indexOf('manager') === -1) { // execute if 'itil' role is not found
    var getImpact = g_form.getValue('impact'); // get selected impact value

    if (getImpact == 1) // impact value 1 
    {
        g_form.removeOption('urgency', '1'); // remove High choice from Urgency
    alert('Only Managers are allowed to select values');
    }
}

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Pratiksha