The CreatorCon Call for Content is officially open! Get started here.

Work notes mandatory when assignment group changes

keerthilatha
Tera Expert

Hi Team,

When a request is re-assigned to a different assignment group I need work_notes to be mandatory.

If I am re-assigning to a different user within the same group work_notes should not to be mandatory.

For that I have written client script onsubmit as follows, but it is not working as expected, please suggest is the syntax is correct or not.

Also please guide how to add logic "When I am re-assigning to a different user within the same group work_notes should not to be mandatory".

function onSubmit() {

    //Type appropriate comment here, and begin script below

 

var x = g_form.getValue('assignment_group');

//.changed from Checking for Modified or Changed Fields in Script - ServiceNow Guru

  if($$('.changed').length > 0 && x == ''){

  g_form.setMandatory('work_notes', true);

  g_form.addErrorMessage(getMessage("Work notes are mandatory when the 'Assignment group' field changes"));

 

  } else {

  return false;

  }

}

1 ACCEPTED SOLUTION

Aakash Shah4
Tera Guru

This is the script



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


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


          return;


    }


if(oldValue != newValue)


{


g_form.setMandatory('work_notes',true);


}




    //Type appropriate comment here, and begin script below


   


}


View solution in original post

19 REPLIES 19

Yes thank you


Hi keerthilatha/Aakash,



I feel you need to modify the code little, We need to check that while assignment Group removed that time This should not trigger right.



Here is the updated code:



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


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


          return;


    }


if(oldValue != newValue && newValue !='')


{


g_form.setMandatory('work_notes',true);


}


}



Thanks,


Arindam


sndangibbard
Mega Guru

I would achieve this with an onChange client script on Assignment Group



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


    if (isLoading) {


          return;


    }



g_form.setMandatory('work_notes', true);


if(newValue==oldValue )


g_form.setMandatory('work_notes', false);


}


But how to add logic "When I am re-assigning to a different user within the same group work_notes should not to be mandatory".


divya mishra
Tera Guru

Hi There,



You can rather use a UI Policy for the same. i.e. Assignment group changes Action = make work notes mandatory


Or if you are using Client script :


onchange of = Assignment group


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


if (isLoading) {  


return;  


}    


if(newValue != oldValue )  


g_form.setMandatory('work_notes', true);  


}



We should worry about changing a different user from the same group as changing assignment group would meet the requirement of making work notes mandatory.



Kindly mark this as useful if it helps