Dynamic Population of Lead Architect Select Box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
- The Lead Architect field should be populated dynamically with relevant users from the IT Architecture Chapter. Only active users with the title containing “Lead Architect” will appear in the list. The list updates automatically based on form changes and does not require a reference field.
script include :
var LeadArchitectList = Class.create();
LeadArchitectList.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAllUsers: function() {
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery(
"department.name=IT Architecture Chapter" +
"^titleLIKELead Architect" +
"^active=true" +
"^ldap_server=8cc39bf5db2a830036c398f3db9619dd" +
"^u_status=aktywny"
);
gr.query();
var users = [];
while (gr.next()) {
users.push({
value: gr.getValue('sys_id'), // wartość do select boxa
label: gr.getDisplayValue('name') // etykieta w select boxie
});
client scripts:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) return;
g_form.clearOptions('lead_architects'); // czyścimy select box
var ga = new GlideAjax('LeadArchitectList');
ga.addParam('sysparm_name', 'getAllUsers');
ga.getXMLAnswer(function(answer) {
console.log('Answer from Script Include:', answer);
if (!answer) return;
var resp = JSON.parse(answer);
if (resp.users && resp.users.length > 0) {
resp.users.forEach(function(u) {
g_form.addOption('lead_architects', u.value, u.label);
});
}
});
}
}
return JSON.stringify({users: users});
},
type: 'LeadArchitectList'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
Czesc @Pawel Barcik.,
what debugging did you do? Any error message?
On first sight - the script include doesn't return anything and the client scrip has addOption() while it's most likely a reference, I don't think that will work.
Have you tried to log it? What's the behaviour - nothing happens, it allows all users not just the leads, or no users, ... please provide some context
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
The script include has multiple problems. The following may work better:
var LeadArchitechList = Class.create();
LeadArchitechList.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAllUsers: function() {
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery(
"department.name=IT Architecture Chapter" +
"^titleLIKELead Architect" +
"^active=true"
"^ldap_server=8cc39bf5db2a830036c398f3db9619dd" +
"^u_status=aktywny"
);
gr.query();
var users = [];
while (gr.next()) {
users.push({
value: gr.getValue('sys_id'), // wartość do select boxa
label: gr.getDisplayValue('name') // etykieta w select boxie
});
}
return users;
},
type: 'LeadArchitechList'
});
Client script appears to be inserted withing the script include code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
try below corrected scripts:
client script-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) return;
g_form.clearOptions('lead_architects');
var ga = new GlideAjax('LeadArchitectList');
ga.addParam('sysparm_name', 'getAllUsers');
ga.getXMLAnswer(function(answer) {
if (!answer) return;
var resp = JSON.parse(answer);
if (resp.users && resp.users.length > 0) {
resp.users.forEach(function(u) {
g_form.addOption('lead_architects', u.value, u.label);
});
}
});
}
script include-
var LeadArchitectList = Class.create();
LeadArchitectList.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAllUsers: function() {
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery(
"department.name=IT Architecture Chapter" +
"^titleLIKELead Architect" +
"^active=true" +
"^ldap_server=8cc39bf5db2a830036c398f3db9619dd" +
"^u_status=aktywny"
);
gr.query();
var users = [];
while (gr.next()) {
users.push({
value: gr.getValue('sys_id'),
label: gr.getDisplayValue('name')
});
}
return JSON.stringify({users: users});
},
type: 'LeadArchitectList'
});