Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

In catalog, we want to set check box as true when condition is true

mounika58
Mega Expert

Below is the code for setting value.

function onChange() {

if (g_form.getValue('variables.UserType') == 'Terminal Server Users')

  {

        g_form.setValue('variables.OutlookEmail',true);

        g_form.setValue('variables.ServiceNowAccount',true);

      g_form.setValue('variables.TerminalAccess',true);

  }

}

When I keep alerts it is showing as true but on the form check box is not getting ticked.

Please help what is missing

1 ACCEPTED SOLUTION

Hi All,



Now it is working after modifying as below.



function onChange() {


//var user = g_form.getValue('variables.UserType');
  if (g_form.getValue('UserType') == 'Terminal Server Users')
  {
        g_form.setValue('OutlookEmail','true');
       
        g_form.setValue('ServiceNowAccount','true');
       
        g_form.setValue('TerminalAccess','true');
     
  }


  else if (g_form.getValue('UserType') == 'External Users with Archroma Laptop')
  {
     


  g_form.setValue('OutlookEmail','true');
  g_form.setValue('ServiceNowAccount','true');
  g_form.setValue('TerminalAccess','false');



  }
     
}


View solution in original post

9 REPLIES 9

Dan Tolgyesi1
Tera Expert

Hi,



You don't need the "variables" part in your setValue, your code should look like: -



function onChange() {



if (g_form.getValue('variables.UserType') == 'Terminal Server Users')


  {


        g_form.setValue('OutlookEmail',true);


        g_form.setValue('ServiceNowAccount',true);


      g_form.setValue('TerminalAccess',true);


  }


}



Please mark your answer as helpful or correct if this has worked.



Thanks,


Dan


Not working Daniel.



function onChange() {


//var user = g_form.getValue('variables.UserType');



  if (g_form.getValue('variables.UserType') == 'Terminal Server Users')
  {
        g_form.setValue('OutlookEmail',true);
        alert(g_form.getValue('variables.OutlookEmail'));
 
  g_form.setValue('ServiceNowAccount',true);
  g_form.setValue('TerminalAccess',true);
  }
  else if (g_form.getValue('variables.UserType') == 'External Users with Archroma Laptop')
  {
      alert('external');


  g_form.setValue('OutlookEmail',true);
  g_form.setValue('ServiceNowAccount',true);
  g_form.setValue('TerminalAccess',false);
  alert(g_form.getValue('variables.TerminalAccess'));
  }


}


I kept alerts and they are popping up correctly but checkboxes are not getting checked. Please let me know what I am missing.


arunram
Kilo Contributor

Hi Mounika,



you can use catalog client script to do this,


Creating a Catalog Client Script - ServiceNow Wiki


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Mounika,



Just remove the variables from your code and it should work.


ex: g_form.setValue('OutlookEmail',true); //Assuming OutlookEmail is the name of the variable.