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.

Use of 'contains' in catalog client script

arohi
Kilo Expert

I have one requirement as there is a reference field( referred to User table). When a user selected next field should appear as per type of user.

User are classified on basis of DN.

So one type is DN = <u_dn>uid=AAA-User,ou=Applications,o=Intra,dc=sears,dc=com</u_dn>

and other is = <u_dn>uid=AAA-User,ou=People,o=Intra,dc=sears,dc=com</u_dn>

I was trying to write a catalog client script on change,

function onChange(control, oldValue, newValue, isLoading) {
    //Type appropriate comment here, and begin script below
      if (isLoading || newValue == '') {
      g_form.setVisible('type_of_access',false);
  g_form.setVisible('access_type',false);
          return;
    }  

var ID = g_form.getValue('select_id_for_access');
var DN = g_form.getValue('ID.u_dn');

//if (DN == '<u_dn>uid=AAA-User,ou=Applications,o=Intra,dc=sears,dc=com</u_dn>')
if(ID.u_dn.indexOf('ou=Applications') >=0)
  {
    g_form.setVisible('type_of_access',true);
  }
if (ID.u_dn == '<u_dn>uid=AAA-User,ou=people,o=Intra,dc=sears,dc=com</u_dn')
  {
    g_form.setVisible('access_type',true);
  }
}

I would like to know how can I use 'Contains' in this script, so that I can add 'DN contains ou=Applications'.

I tried using 'indexof' but it wasn't much helpful.

Please suggest.

TIA.

1 ACCEPTED SOLUTION

vinothkumar
Tera Guru

Hi Arohi,



getValue() will just give the sys_id of the reference field.   Can you try by using the getReference() Method, something similar as below



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


    //Type appropriate comment here, and begin script below


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


      g_form.setVisible('type_of_access',false);


  g_form.setVisible('access_type',false);


          return;


    }  




//var ID = g_form.getValue('select_id_for_access');


//var DN = g_form.getValue('ID.u_dn');




var ID = g_form.getReference('select_id_for_access', doAlert);




function doAlert(ID)


{




//if (DN == '<u_dn>uid=AAA-User,ou=Applications,o=Intra,dc=sears,dc=com</u_dn>')


if(ID.u_dn.indexOf('ou=Applications') >=0)


  {


    g_form.setVisible('type_of_access',true);


  }


if (ID.u_dn == '<u_dn>uid=AAA-User,ou=people,o=Intra,dc=sears,dc=com</u_dn')


  {


    g_form.setVisible('access_type',true);


  }


}


}


View solution in original post

3 REPLIES 3

Harsh Vardhan
Giga Patron

have you tried with below example.



contains[Short description][contains][SAP]
  • *
  • LIKE
short_descriptionLIKESAP



http://wiki.servicenow.com/index.php?title=Operators_Available_for_Filters_and_Queries#gsc.tab=0


vinothkumar
Tera Guru

Hi Arohi,



getValue() will just give the sys_id of the reference field.   Can you try by using the getReference() Method, something similar as below



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


    //Type appropriate comment here, and begin script below


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


      g_form.setVisible('type_of_access',false);


  g_form.setVisible('access_type',false);


          return;


    }  




//var ID = g_form.getValue('select_id_for_access');


//var DN = g_form.getValue('ID.u_dn');




var ID = g_form.getReference('select_id_for_access', doAlert);




function doAlert(ID)


{




//if (DN == '<u_dn>uid=AAA-User,ou=Applications,o=Intra,dc=sears,dc=com</u_dn>')


if(ID.u_dn.indexOf('ou=Applications') >=0)


  {


    g_form.setVisible('type_of_access',true);


  }


if (ID.u_dn == '<u_dn>uid=AAA-User,ou=people,o=Intra,dc=sears,dc=com</u_dn')


  {


    g_form.setVisible('access_type',true);


  }


}


}


arohi
Kilo Expert

Thank you all for response!


Amongst all Vinoth's solution worked perfectly.


Thanks Vinoth!