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

Hi Divya,



Just make a note : Changes condition is not in UI policy. That condition is in Business rule condition builder.


Please check this


well I missed that, did the client script helped?


User674480
Tera Contributor

Hi Keerthilatha,



Create an onChange() client script on that table with Field Name 'Assignment Group' and below is the code. I have created the onChange() client script on incident table for testing purpose.




find_real_file.png



Please hit Like or Helpful or mark your question as answered if it resolves your issue.



Regards,


Sanjeeva Reddy.


Would anybody know how this script could be edited to enforce only when the assignment group changes from one to another rather than any change?


Currently work notes mandatory is true for any change so even on first assignment, empty>first assignment group.



Thanks!


Hi Ben,



We've updated the client script code to do exactly the same scenario you described. Try the code below:



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


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


              return;


      }


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


      {


              g_form.setMandatory('work_notes', true);


              g_form.addErrorMessage('Work note is required.');


              g_form.showFieldMsg("work_notes", "Enter a work note then click Update/Save", "error");


      }


      if(newValue == oldValue){


              g_form.setMandatory('work_notes', false);


              g_form.addInfoMessage('Assignment Group is returned to original value.');


              g_form.hideFieldMsg("work_notes");


      }


}