- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2020 04:34 AM
Hi,
I'm building a form that when a user is selected, I can populate an options list. Whilst I can manually populate the list, I am unable to look up the values I'd like using the GlideRecord Command.
I've added the Isolate Script box and unticked it as the help advised, but still no records are returned (confirmed using the alert command I've added in - see the screenshot). I've tested the script in isolation and it runs fine, so is this a restriction of where I'm trying to run it, and if so, any ideas how I get around it?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2020 06:54 AM
Hi,
this is client script,
function onChange(control, oldValue, newValue, isLoading) {
}
script include:
var populateManager = Class.create();
});
Use this code and replace fields with your matching table fields. Use array concept given here you can check the records in drop down list.
Please mark it as helpful/correct based on impact.
Thanks
Darshani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2020 04:36 AM
As you are calling this client-side, you will need to use GlideAjax to send a request to the server and return the information.
Here is an example that pulls records from the cmdb_ci_spkg table and populates a select box named "software" with options.
Name: populateSelectBox
Client-Callable = true
var populateSelectBox = Class.create();
populateSelectBox.prototype = Object.extendsObject(AbstractAjaxProcessor, {
type: 'populateSelectBox',
getSoftware: function() {
//Queries the cmdb_ci_spkg table for all records with the attribute showInPortal
//and constructs a JSON Object as a response with name and sys_id
var retStr = [];
var jStr = '[';
var gr_software = new GlideRecord('cmdb_ci_spkg');
gr_software.addEncodedQuery('attributesLIKEshowInPortal');
gr_software.orderBy('name');
gr_software.query();
while (gr_software.next()) {
jStr += '{"name":"' + gr_software.getValue('name') + '","id":"' + gr_software.getValue('sys_id') + '"},';
}
jStr = jStr.substring(0, jStr.length - 1);
jStr += "]";
return jStr;
}
});
Then, in your catalog call this script onload to set the values (this assumes that none was included in the variable definition). Just replace "software" with the name of your variable.
function onLoad() {
//Call GlideAjax to populate the software list
var ga = new GlideAjax('populateSelectBox');
ga.addParam('sysparm_name', 'getSoftware');
ga.getXML(ajProcessor);
function ajProcessor(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var obj = JSON.parse(answer);
var i;
for (i = 0; i < obj.length; i++) {
//replace software with your variable name
g_form.addOption('software', obj[i].id, obj[i].name);
}
}
}
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2020 04:38 AM
Hi
Using GlideRecord in client side is not a best practice to follow, instead use GlideAjax and script include behavior to achieve your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2020 06:24 AM
Crikey. Ok. I'll give that a go. I'll let you know how I get on.
Thank you very much!
Kind Regards,
Mark.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2020 06:54 AM
Hi,
this is client script,
function onChange(control, oldValue, newValue, isLoading) {
}
script include:
var populateManager = Class.create();
});
Use this code and replace fields with your matching table fields. Use array concept given here you can check the records in drop down list.
Please mark it as helpful/correct based on impact.
Thanks
Darshani