- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 01:33 AM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 01:55 AM
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);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 01:41 AM
have you tried with below example.
contains | [Short description][contains][SAP] |
| short_descriptionLIKESAP |
http://wiki.servicenow.com/index.php?title=Operators_Available_for_Filters_and_Queries#gsc.tab=0

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 01:55 AM
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);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2017 02:18 AM
Thank you all for response!
Amongst all Vinoth's solution worked perfectly.
Thanks Vinoth!