How to construct if statement based on state change and assignment group

chrisn_
Mega Guru

Hello everyone,

I am trying to restrict a client script running on our incident form to only run for certain assignment groups. My code below is checking for the change in state so that when someone resolves their incident they are sternly reminded to fill out their time worked field accurately. This part works, but the thing that is stumping me is that I need to restrict this to only run for a specific list of assignment groups. Should this be a new if statement nested inside or should the if statement that compares the old and new values be expanded or none of the above?

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

if (isLoading || newValue === '') {

return;

}

//Alert message if dispostion changes
var view = getView();
if (view == ''){ //default view name is blank
if ((oldValue == '1' || oldValue == '2' || oldValue == '3' || oldValue == '4' || oldValue == '5') && (newValue == '6' || newValue =='7' )) {
g_form.addInfoMessage('Please update your Time worked.');
g_form.showFieldMsg("time_worked", "Please update your Time worked", "error");
var tabIndex = g_tabs2Sections.findTabIndexByName('Billable Hours');
g_tabs2Sections.setActive(4);
g_form.setMandatory('time_worked',true);
g_form.flash("incident.time_worked", "RED", -2);
}
}
}

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

If you only want it to run for 'x' groups then you'd want to have that in there. I'd have this on the outside, being evaluated first. And then the other IF's nested.

if (g_form.getDisplayValue('assignment_group') == 'Helpdesk Support' || etc. etc. || etc. etc.) {

}


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

5 REPLIES 5

Allen Andreas
Administrator
Administrator

If you only want it to run for 'x' groups then you'd want to have that in there. I'd have this on the outside, being evaluated first. And then the other IF's nested.

if (g_form.getDisplayValue('assignment_group') == 'Helpdesk Support' || etc. etc. || etc. etc.) {

}


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen,

I have the same requirements and cannot seem to get the script to work. I added the code you mentioned but no success.

Do you mind sharing the entire working script?

 

===============================

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

if (isLoading || newValue === '') {

return;

 


if (g_form.getDisplayValue('assignment_group') == 'ServiceNow Admin'){
}

//Alert message if dispostion changes
var view = getView();
if (view == ''){ //default view name is blank
if ((oldValue == '1' || oldValue == '-6') && (newValue == '2' || newValue == '3' || newValue == '-7' || newValue =='-8' )) {
g_form.addInfoMessage('Please update your Time worked.');
g_form.showFieldMsg("time_worked", "Please update your Time worked", "error");
var tabIndex = g_tabs2Sections.findTabIndexByName('Billable Hours');
g_tabs2Sections.setActive(4);
g_form.setMandatory('time_worked',true);
g_form.flash("incident.time_worked", "RED", -2);
}
}
}

Hi,

The author would be the one with the actual script to use. As far as what you've done, do you have a field/the correct field chosen for your onChange client script? Sometimes people don't pick one or pick the wrong field used for evaluation.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

GChanner
Tera Guru

Hi Chrisn,

Were you able to get this script to work by validating the assignment group?

I have the same requirements and cannot seem to get the script to work. I added the code Allen mentioned but no success.

Do you mind sharing the entire working script?