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-23-2024 06:21 AM
The error in this case is due to the Script Include being unreachable. You need to make the script Client callable to work with the GlideAjax call. If checking the box doesn't change the existing script, here's what it should look like:
var DirectReporteesUtil = Class.create();
DirectReporteesUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDirectReportees: function() {
var managerSysId = this.getParameter('managerSysId');
var reportees = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', managerSysId);
gr.query();
while (gr.next()) {
reportees.push(gr.sys_id.toString());
}
return reportees.join(',');
},
type: 'DirectReporteesUtil'
});
This also defines the parameter you're passing in from the Client Script, and returns a simple comma-separated list of sys_ids.
In the Client script, all you should need to do is set the value from the response:
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) {
g_form.setValue('list_of_direct_reportees', response);
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 10:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 11:24 AM
I noticed in the Client Script you are calling a Script Include in the sn_hr_core scope, but the one you have pictured is in the Global scope. If the Catalog Item / Client Script are in the Global scope you can leave this out, otherwise change the GlideAjax call to
var ga = new GlideAjax('global.DirectReporteesUtil');
If it's still not working we can temporarily add some logs to confirm the Script Include is running, etc. If you don't see any of these, change them to gs.info then look in System > Logs and search on Messages starting with si21
var DirectReporteesUtil = Class.create();
DirectReporteesUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDirectReportees: function() {
var managerSysId = this.getParameter('managerSysId');
gs.addInfoMessage('si21 SI running - managerSysId = ' + managerSysId
var reportees = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', managerSysId);
gr.query();
while (gr.next()) {
gs.addInfoMessage('si21 - added to array ' + gr.name)
reportees.push(gr.sys_id.toString());
}
gs.addInfoMessage('si21 - returning ' + reportees.join(',');
return reportees.join(',');
},
type: 'DirectReporteesUtil'
});