Location does not show anything

Alon Grod
Tera Expert

Hi, 

Im trying to show a list of options under Location field when creating a new user in sys_user table.

What am I doing wrong?

getLocations: function() {
        var arr = [];
        var gr = new GlideRecord("cmn_location");
        gr.addQuery();
        gr.query();
        while(gr.next()) {
            arr.push(gr.getValue('name'));
        }
        return arr.toString();
    },

 

1 ACCEPTED SOLUTION

Vasantharajan N
Giga Sage
Giga Sage

1. Please update your script to return array of sys_id 

getLocations: function() {
        var arr = [];
        var gr = new GlideRecord("cmn_location");
        gr.addQuery();
        gr.query();
        while(gr.next()) {
            arr.push(gr.getValue('sys_id'));
        }
        return arr.toString();
    }

2. Update your reference qualifier to 'sys_idIN'+new CSManagementUtils.getLocations();

find_real_file.png

then check.

 


Thanks & Regards,
Vasanth

View solution in original post

4 REPLIES 4

Mark Manders
Mega Patron

What exactly do you want to show? This query indeed isn't going to show anything. Please provide us with the requirement so we can help creating the correct one.

If my answer helped you in any way, please then mark it as helpful.

Mark


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

hi Mark,

im trying to show location values from cmn_location table

You script include is just getting all locations in the system, so why do you need a reference qualifier at all?


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Vasantharajan N
Giga Sage
Giga Sage

1. Please update your script to return array of sys_id 

getLocations: function() {
        var arr = [];
        var gr = new GlideRecord("cmn_location");
        gr.addQuery();
        gr.query();
        while(gr.next()) {
            arr.push(gr.getValue('sys_id'));
        }
        return arr.toString();
    }

2. Update your reference qualifier to 'sys_idIN'+new CSManagementUtils.getLocations();

find_real_file.png

then check.

 


Thanks & Regards,
Vasanth