- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 04:52 PM
We currently have a UI Action that calls a UI Macro/ UI Page and includes a script include. I want the returned names to display alphabetically by first name, then last name. Ideas on how to implement?
Script Include:
var SoftwareAjax = Class.create();
SoftwareAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSoftwareOptions: function() {
var result = [];
// Query the 'alm_license' table for available software records
var gr = new GlideRecord('alm_license');
gr.addQuery('active', true); // Add additional filters as needed
gr.query();
// Loop through the results and push them into the result array
while (gr.next()) {
result.push({
value: gr.getValue('sys_id'),
text: gr.getValue('name') // Replace 'name' with the appropriate field
});
}
// Log the result for debugging
gs.log("SoftwareAjax - Retrieved Software Options: " + JSON.stringify(result));
// Return the result as a JSON string
return JSON.stringify(result);
},
type: 'SoftwareAjax'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 05:05 PM
Hi Julia,
You can sort the array before or after returning it, but in this example you could also add a line to the GlideRecord before the gr.query();
gr.orderBy('name');
or whatever field(s) are on the alm_license records that contain a first name and last name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 05:05 PM
Hi Julia,
You can sort the array before or after returning it, but in this example you could also add a line to the GlideRecord before the gr.query();
gr.orderBy('name');
or whatever field(s) are on the alm_license records that contain a first name and last name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 05:23 PM
Thank you! I was way overcomplicating that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 05:36 PM