- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2025 01:54 PM
When a user clicks on a checkbox in the Incident Form, a list of active users should be displayed.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2025 07:56 AM
you can use GlideDialogWindow for this to show the list
create onChange client script and use this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue == "true") {
var w = new GlideDialogWindow('show_list');
w.setTitle('Active Users');
w.setPreference('table', 'sys_user_list');
w.setPreference('sysparm_view', 'default');
var query = 'active=true';
w.setPreference('sysparm_query', query);
//Open the popup
w.render();
}
}
This is how the output will look like
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2025 07:51 AM
Hi @Kanhaiya_Verma ,
Steps to Implement
Create a New Field
- Navigate to System Definition > Tables.
- Select the Incident table.
- Add a new field:
- Type: Checkbox
- Label: Show Active Users
- Name: u_show_active_users.
Add a Reference Field for Users
- Add another field in the Incident table:
- Type: List (Reference).
- Label: Active Users.
- Name: u_active_users.
- Reference: User [sys_user].
- Add another field in the Incident table:
Client Script for Checkbox Behavior
- Navigate to System Definition > Client Scripts.
- Create a new Client Script:
- Name: Show Active Users on Checkbox Click.
- Table: Incident.
- Type: OnChange.
- Field: u_show_active_users.
- Script:
(function executeRule(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue == oldValue) { return; } if (newValue) { // Perform a GlideAjax call to fetch active users var ga = new GlideAjax('FetchActiveUsers'); ga.addParam('sysparm_name', 'getActiveUsers'); ga.getXMLAnswer(function(response) { var users = JSON.parse(response); g_form.clearOptions('u_active_users'); // Clear existing options users.forEach(function(user) { g_form.addOption('u_active_users', user.sys_id, user.name); }); }); } else { g_form.clearOptions('u_active_users'); // Clear options if unchecked } })(g_form.getControl('u_show_active_users'), '', '', false, false);
Script Include for Fetching Active Users
- Navigate to System Definition > Script Includes.
- Create a new Script Include:
- Name: FetchActiveUsers.
- Accessible from: Client Callable.
- Script:
var FetchActiveUsers = Class.create(); FetchActiveUsers.prototype = { initialize: function() {}, getActiveUsers: function() { var userList = []; var gr = new GlideRecord('sys_user'); gr.addQuery('active', true); gr.query(); while (gr.next()) { userList.push({ sys_id: gr.getValue('sys_id'), name: gr.getValue('name') }); } return JSON.stringify(userList); }, type: 'FetchActiveUsers' };
Test the Functionality
- Open the Incident form.
- Check the Show Active Users checkbox.
- The Active Users list should populate with active users.
Explanation
- Client Script: Handles the onChange event for the checkbox to fetch users dynamically using GlideAjax.
- Script Include: Fetches active users from the sys_user table and returns the data to the client script.
- Reference Field: Displays the list of active users dynamically on the form.
Best regards,
Siddhesh Jadhav
If this solution helps resolve your query, kindly mark my answer as helpful and accepted. Let me know if you need further assistance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2025 07:56 AM
you can use GlideDialogWindow for this to show the list
create onChange client script and use this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue == "true") {
var w = new GlideDialogWindow('show_list');
w.setTitle('Active Users');
w.setPreference('table', 'sys_user_list');
w.setPreference('sysparm_view', 'default');
var query = 'active=true';
w.setPreference('sysparm_query', query);
//Open the popup
w.render();
}
}
This is how the output will look like
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2025 06:39 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2025 07:39 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader