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

Hi GChanner, 

I did get it to work, I had to do it with a couple business rules as my instance wanted to do it with incident, and project amongst other task types.

The business rule triggers when the state changes to resolved or closed + the assignment group is {insert assignment group}. I had to do that manually for each one in the when to run condition builder. As for the script it turns here it is. The script is checking to see if the time worked has changed, not if there is time there, so if they had put in 10 minutes last time they checked and try to close it they will get yelled at as they did not alter the time when trying to resolve the incident.

 

var updateInitiatedBy = updateInitiatedBy || current.sys_id.toString();

(function executeRule(current, previous /*null when async*/) {

if(updateInitiatedBy == current.sys_id.toString()){

var start = previous.time_worked.dateNumericValue();


var end = current.time_worked.dateNumericValue();


var diff = end - start;


if (diff == 0){


gs.addErrorMessage('You must enter your Time worked under Billable Hours. Your updates to this record are still in place, but will not be entered until Time worked has been updated. ');


current.setAbortAction(true);


}

 

}
})(current, previous);