auto populate multiple users in a field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 09:45 AM
Hi experts,
We have a requirement to show all the reports of a manager in a question. Not a reference field. All the users must be visible on the field without even selecting(like list collector).
Is it feasible?
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 10:21 AM
A List field / List Collector variable is your only choice for selecting more than one value. onLoad or onChange of the selected manager field/variable, you could have the list field/variable populate all of the user records with that manager via a client script that calls a GlideAjax.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 05:39 AM
Hi @Brad Bowman ,
I have tried using script include and onchange client script following community articles but list collector is not getting autopoulated. Could you please help me with the code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 05:43 AM
Sure. Post your scripts using the insert code icon </> and I'll take a look.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 05:50 AM
Here is the code which I used, error is saying as 'There is a JavaScript error in your browser console'
-----script include----------
var DirectReporteesUtil = Class.create();
DirectReporteesUtil.prototype = {
initialize: function() {},
getDirectReportees: function(managerSysId) {
var reportees = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', managerSysId);
gr.query();
while (gr.next()) {
reportees.push({
sys_id: gr.sys_id.toString(),
name: gr.name.toString()
});
}
return JSON.stringify(reportees); // Return as JSON string
},
type: 'DirectReporteesUtil'
};
----clientscript---
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return; // Do nothing if the form is loading or no manager is selected
}
var ga = new GlideAjax('DirectReporteesUtil');
ga.addParam('sysparm_name', 'getDirectReportees');
ga.addParam('managerSysId', newValue); // Use the new manager's sys_id
ga.getXMLAnswer(function(response) {
var reportees = JSON.parse(response);
var listCollector = g_form.getControl('list_of_direct_reportees'); // Replace with your List Collector field name
// Clear existing values
listCollector.value = '';
// Populate the List Collector
for (var i = 0; i < reportees.length; i++) {
var option = new Option(reportees[i].name, reportees[i].sys_id);
listCollector.add(option);
}
});
}