SetValue using sys_id

marskh1111
Kilo Contributor

My client needs the assigned to field to be mandatory for certain users. The issue I am having is the client also needs to assignment group to not show in this same situation. We have the assigned to field as a reference to the assignment group. I tried using the following script in a client script and it is not functioning as I thought it would. The assignment group is showing up false and the assigned to field no longer as the correct options under it.

Here is my script:

function onLoad() {

  if (g_user.hasRole('test_user) && !g_user.hasRole('admin_user)){

  g_form.setMandatory('assignment_group', false);

  g_form.setDisplay('assignment_group', false);

      g_form.setValue('assignment_group', '(sys id here', 'display value here');

        g_form.setMandatory('assigned_to);

  }else{

  g_form.setDisplay('assignment_group', true);

  }

}

7 REPLIES 7

Thanks all for your help. It was as simple as for some reason the sys_id wasn't mapping to the righ tcompany found the right sys id and works great. Thanks for all your help!


Thanks Kimberly for the update.


Can you please mark the correct response and close the loop if your query is resolved now.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Kimberly,




1. Error in line     g_form.setMandatory('assigned_to); should     g_form.setMandatory('assigned_to', true);


Client Scripts - ServiceNow Wiki