Catalog Variable populated by script shows SYS_ID on RITM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2024 05:30 AM
We have a Location variable with 4 possible choices on it (Select Box - It's actually a list of 4 countries). When a user makes a selection a client script calls a script include which matches that location with records on a cmn_location table which are then sent back with labels to populate another Select Box so the user can select which "building" they are making the request for.
For example, the top field informs the bottom fields (some fields removed from screenshot for security):
The problem is that on the RITM view, the label isn't showing. Instead we only see the sys_id. Is there a way to make it show the label on RITM view?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2024 05:35 AM
Please show the client script that is supposed to set the values of the buildings.
See more of my content here.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2024 06:17 AM
Thank you.
The client script is:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var location = g_form.getValue('room_location');
var populateBuilding = new GlideAjax('AvMeetingPopulateLocationAjax');
populateBuilding.addParam('sysparm_name', 'populateLocation');
populateBuilding.addParam('sysparm_location', location);
populateBuilding.getXML(populateBuildingField);
}
function populateBuildingField(response) {
g_form.clearOptions('room_building2'); //clears all choices from room_building2
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer) {
var responseArray = JSON.parse(answer);
for (var i = 0; i < responseArray.length; i++) {
//Adds each label and ID returned, to Building choice box
g_form.addOption('room_building2', '', '-- None --', '0');
g_form.addOption('room_building2', responseArray[i].id, responseArray[i].label);
}
}
}
onChange and set to apply to Catalog and RITM views (although I realise that it won't work on the RITM view as I'm not changing anything).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2024 07:55 AM
@Andrew Bettcher Did you add an alert to print the answer received from the server? Does it contain the location name and sys_id pair?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2024 06:32 AM
This is the script include:
var AvMeetingPopulateLocation = Class.create();
AvMeetingPopulateLocation.prototype = {
initialize: function() {
/*This script contains hardcoded sys_ids. The only alternative
was to store each countries cmn_locations in sys_properties but
this would make it complex to update in case new locations were
required
To add new locations, add the location sys_id to this.offices with
a descriptive key and then call it from this.countryLocation in
the relevant country object. Key cannot begin with a number and
should not contain spaces,
Labels are initially invalid and then replaced by loop below for display
If location record isn't found "invalid" will show in select box*/
this.offices = {
TowerDubai: { label: "invalid", id: "99fb64a5db807740adf3e2e15b961980" },
GrosvenorHouse: { label: "invalid", id: "004eb4cd1bcf3b0007bf21ff6e4bcb51" },
CanadaSquare: { label: "invalid", id: "96783ab4db40d4d445cdd06b68961958"},
CentenarySquare: { label: "invalid", id: "80fba0a5db807740adf3e2e15b9619ea" },
CorkStreet: { label: "invalid", id: "cdfb64a5db807740adf3e2e15b961942" },
QueensRoadHK: { label: "invalid", id: "58fbe0a5db807740adf3e2e15b96196b" },
TseungKwanOHK: { label: "invalid", id: "c451ea68db0814d4662ed8e74b961969" },
HudsonNYC: { label: "invalid", id: "b748ac681bd56950b88ca609b04bcb59" },
LarkinBuffalo: { label: "invalid", id: "f748ac681bd56950b88ca609b04bcb5a" },
};
// loop through this.offices getting correct labels
for (var key in this.offices) {
var grLOCN = new GlideRecord('cmn_location');
if (grLOCN.get(this.offices[key].id)) {
this.offices[key].label = grLOCN.getDisplayValue('name');
}
}
this.countryLocation = {
'uae': [
this.offices.TowerDubai
],
'unitedkingdom': [
this.offices.GrosvenorHouse,
this.offices.CanadaSquare,
this.offices.CentenarySquare,
this.offices.CorkStreet
],
'hongkong': [
this.offices.QueensRoadHK,
this.offices.TseungKwanOHK
],
'usa': [
this.offices.HudsonNYC,
this.offices.LarkinBuffalo
]
};
},
populateLocation: function(location) {
/*pass in the location value and use it to access the relevant
country object and return the sys_ids*/
var responseObj = JSON.stringify(this.countryLocation[location]);
return responseObj
},
type: 'AvMeetingPopulateLocation'
};