Need help to fix the onChange Client Script

Pooja Khatri
Tera Contributor

Hi All ,

I am facing issue with the below onChange Client script on Impact and URGENCY Field, as per the below script
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- This is Working perfectly fine

 

Issues which I am facing in the below code :

 

1) Code is not working for users with admin role
2) When they try to change back the option from 1 - widespread in IMPACT or High in URGENCY to any other value all the dropdown fields in IMPACT and URGENCY should be visible back which is not working correct

 

Where is my script wrong?

 

OnChange Client Script on Urgency Field : 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var userRole = g_user.hasRole('manager');
var geturgency = newValue;
if (!userRole && geturgency == 1) {
g_form.removeOption('impact', 1);
}
}

 

OnChange Client Script on IMPACT Field

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

var userRole = g_user.hasRole('manager');
alert(userRole);
var getImpact = newValue; // selected impact value
if (!userRole && getImpact == 1) //impact value 1 for high
{
g_form.removeOption('urgency', 1);
}
}

 

Can anyone help me to fix the script ?

1 REPLY 1

AshishKM
Kilo Patron
Kilo Patron

Hi @Pooja Khatri , 

Add alert inside the if condition and check if control goes inside that or not, if not then condition not true.

 

-Thanks,
AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution