- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 06:34 AM
Hi Team,
i have a requirement on the catalog form i have two variables on the catalog form
1)requested_for(reference to user table)
2)location(reference to location table)
When ever requested for user is indian location referece variable need to display few indian location for selecting the user. for other than indians location field need to populate corresponding user location (in the sys user table).
I have written below script
javascript: new Populate_Indian_location().fetchingLocation(current.variables.cr_requested_for);//reference qulifier on the location variable.
Script include:
var Populate_Indian_location = Class.create();
Populate_Indian_location.prototype = {
fetchingLocation: function(userdata) {
var grUser1 = new GlideRecord('sys_user');
grUser1.get(userdata);
if (grUser1.isValidRecord())
country = grUser1.location.u_core_country.iso3166_2.getDisplayValue();
gs.log("user country list" + country);
if (country == 'IN') {
var array = [];
var gr2 = new GlideRecord('cmn_location');
gr2.addEncodedQuery('name=AP-IN-Hyderabad-CGSC^ORname=AP-IN-Savli-II^ORname=AP-IN-Lote');
gr2.query();
gs.log("list of records country" + gr2.getRowCount());
while (gr2.next()) {
array.push(gr2.sys_id);
}
var sysLoc = array.toString();
return 'sys_idIN' + sysLoc;
I am not able to get the solution
Could you please Help on this .
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 10:42 AM
@hari kumar Where are you facing the issue? Is your fetching location function not returning the sys Ids? Here is one one improvement I did in your script include.
var Populate_Indian_location = Class.create();
Populate_Indian_location.prototype = {
fetchingLocation: function(userdata) {
var grUser1 = new GlideRecord('sys_user');
grUser1.get(userdata);
if (grUser1.isValidRecord())
country = grUser1.location.u_core_country.iso3166_2.getDisplayValue();
gs.log("user country list" + country);
if (country == 'IN') {
var array = [];
var gr2 = new GlideRecord('cmn_location');
gr2.addEncodedQuery('name=AP-IN-Hyderabad-CGSC^ORname=AP-IN-Savli-II^ORname=AP-IN-Lote');
gr2.query();
gs.log("list of records country" + gr2.getRowCount());
while (gr2.next()) {
array.push(gr2.getValue('sys_id'));//Updated this line
}
var sysLoc = array.toString();
return 'sys_idIN' + sysLoc;
Whenever, you push a value in an array, always use getValue instead of dot walking otherwise the sys_id of the last record would get repeated on all array indexes.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 10:42 AM
@hari kumar Where are you facing the issue? Is your fetching location function not returning the sys Ids? Here is one one improvement I did in your script include.
var Populate_Indian_location = Class.create();
Populate_Indian_location.prototype = {
fetchingLocation: function(userdata) {
var grUser1 = new GlideRecord('sys_user');
grUser1.get(userdata);
if (grUser1.isValidRecord())
country = grUser1.location.u_core_country.iso3166_2.getDisplayValue();
gs.log("user country list" + country);
if (country == 'IN') {
var array = [];
var gr2 = new GlideRecord('cmn_location');
gr2.addEncodedQuery('name=AP-IN-Hyderabad-CGSC^ORname=AP-IN-Savli-II^ORname=AP-IN-Lote');
gr2.query();
gs.log("list of records country" + gr2.getRowCount());
while (gr2.next()) {
array.push(gr2.getValue('sys_id'));//Updated this line
}
var sysLoc = array.toString();
return 'sys_idIN' + sysLoc;
Whenever, you push a value in an array, always use getValue instead of dot walking otherwise the sys_id of the last record would get repeated on all array indexes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 11:22 AM
Hi Team,
i have a requirement on the catalog form i have two variables on the catalog form
1)requested_for(reference to user table)
2)location(reference to location table)
When ever requested for user is indian location referece variable need to display few indian location for selecting the user. for other than indians location field need to populate corresponding user location (in the sys user table).
I have written below script
javascript: new Populate_Indian_location().fetchingLocation(current.variables.cr_requested_for);//reference qulifier on the location variable.
Script include:
var Populate_Indian_location = Class.create();
Populate_Indian_location.prototype = {
fetchingLocation: function(userdata) {
var grUser1 = new GlideRecord('sys_user');
grUser1.get(userdata);
if (grUser1.isValidRecord())
country = grUser1.location.u_core_country.iso3166_2.getDisplayValue();
gs.log("user country list" + country);
if (country == 'IN') {
var array = [];
var gr2 = new GlideRecord('cmn_location');
gr2.addEncodedQuery('name=AP-IN-Hyderabad-CGSC^ORname=AP-IN-Savli-II^ORname=AP-IN-Lote');
gr2.query();
gs.log("list of records country" + gr2.getRowCount());
while (gr2.next()) {
array.push(gr2.sys_id);
}
var sysLoc = array.toString();
return 'sys_idIN' + sysLoc;
I am not able to get the solution
Could you please Help on this .
but form is onloading its not working
Below script is onload script:
when ever login person is indian or other country person by default user location based it auto populate. location variable by default :javacript:gs.getUser().getRecord().getValue('location')
but we have removed this default ::javacript:gs.getUser().getRecord().getValue('location')
Because of above onchange script based on location only display on location referece field
How to fix the issue