Making Worknotes mandatory when changing assignment group in any state of catalog task .

Chaithu3
Tera Contributor

VERY IMPORTANT..  URGENT..!!

Whenever an assignment group is changed in any state(i.e. open , work in progress , blocked , pending , onhold , close complete , close incomplete , close skipped) worknotes should be mandatory . User should provide reason for assignment group change.

Please create a new new business rule on Catalog Task table(sc_task ) which runs on update call .
Below are the filter condition for BR
State is Anything and Assignment group changes
worknotes should be mandatory.

 

ANYONE PLEASE HELP ME WITH A CODE IN BUSINESS RULE

@Ankur Bawiskar  @Pradeep Sharma 

1 ACCEPTED SOLUTION

P-Rudenko-SN
ServiceNow Employee
ServiceNow Employee

So let me explain to you what my first script does. The code is triggered, once you set the NEW value into the assignment group. It checks the following:

IF the new value of 'Assignment Group' is different than the old value (the one was there when the form is loaded) AND the 'State' field is 'Open/Work in Progress/Pending' then it makes the 'Work notes' field mandatory. Please NOTE: if you changed the assignment group, set the status to 'Open/Work in Progress/Pending' and the work note became mandatory, then IF you do not submit the for but try to change the state to not of these there above (let's say 'Closed complete'), then, OF COURSE, the work notes will REMAIN to be mandatory because the 'Assignment group' is still other then it was when the form is loaded.

You cannot expect the 'work_notes' field to be set back to the optional if you change the state to another one BUT the Assignment Group field contains the new value. You have to save the ticket and afterward change it to the new state. The client script is constantly checking the assignment group field. This is its nature, otherwise, you can't control the change of assignment group field. I hope it now finally makes sense.

 

View solution in original post

28 REPLIES 28

Apologies, I did a small mistake in the script. Yes, create an 'onChange' client script for 'sc_task' table for the field 'Assignment Group'.

Here is the script to use:

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

var st = g_form.getValue('state');	
if((st == 1) || (st == 2) || (st == -5))   
g_form.setMandatory('work_notes', true);
	
   //Type appropriate comment here, and begin script below
   
}

I tested it on my PDI and it works fine. Let me know if it's good for you now.

Hi @Pavlo Rudenko 

i have used the same script, But still it is not working..

it is working when ive changed the assignment group and state to work in progress without saving then i changed it to closed complete still the work notes is showing mandatory.

 

Thanks

 

Please keep in mind, that as you already changed the 'Assignment group', it would not bring the 'work_notes' field back to optional. This is the requirement you explained to me.

I've now extended the script to set the work note to optional if the fields are back to initial values. Please try this one:

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

var st = g_form.getValue('state');	
if((newValue != oldValue) && ((st == 1) || (st == 2) || (st == -5)))
g_form.setMandatory('work_notes', true);
else g_form.setMandatory('work_notes', false);
	
   //Type appropriate comment here, and begin script below
   
}

Hi @Pavlo Rudenko 

Sorry for that 

Still the code is not working as expected

when i change the assignment group then the state changes to open then the worknotes showing mandatory then im changing the state to close complete still the worknotes is showing mandatory.

when i change the state from open to closed complte/incomplete after changing of assignment group still showing worknotes mandatory.

 

Thanks.

"when i change the assignment group then the state changes to open then the worknotes showing mandatory then im changing the state to close complete still the worknotes is showing mandatory."

Of course, it does! because in this case "Assignment group" is not the same as it was when the form loaded! if you set the state to 'closed complte/incomplete' AND put the assignment group as it was when you opened the form, then the field becomes optional.

Please keep in mind, that condition for the mandatory field is state (open, wip ....) AND the Assignment group NOT equal then it was when the form is loaded (meaning the field is changed). 

So the behavior you've just explained is absolutely correct according to the requirements you've provided. Please check the script logic and your requirement, so we can finally close this thread.