- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 11:48 PM - edited 05-14-2025 12:54 AM
Hello,
I have an requirement where i need to pull all group names based on user on employee profile table to update automatically on list field.
need one time script / Fix script to update these in one short
if anyone can help me on this
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 11:56 PM
use below script in your fix scritp:
(function executeFixScript() {
// Define the user field and the employee profile table
var employeeProfileGR = new GlideRecord('x_your_custom_employee_profile'); // Replace with your actual table name
employeeProfileGR.query();
while (employeeProfileGR.next()) {
var user = employeeProfileGR.getValue('user'); // Adjust the field name as needed
if (!user) continue;
var groupList = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', user);
gr.query();
while (gr.next()) {
var groupName = gr.group.name.toString();
groupList.push(groupName);
}
// Join group names with comma and space, or just comma if that's the requirement
var groupListStr = groupList.join(', ');
// Assuming there is a list field or string field to store group names
employeeProfileGR.setValue('group_list_field', groupListStr); // Replace 'group_list_field' with your field name
employeeProfileGR.update();
}
gs.info('Fix script to update user groups in employee profile completed.');
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 11:50 PM
@lakshmi_laksh wrote:Hello,
I have an requirement where i need to pull all group names based on user on employee profile table to update automatically on list field.
need one time script / Fix script to update these in one short
if anyone can help me on this
Thanks in advance.
Hello @lakshmi_laksh,
To achieve this, you can use a script to query the employee profile table and fetch group names based on the user. Then, update the list field dynamically. Ensure the script filters relevant groups and handles updates efficiently. If you're using a platform like ServiceNow, GlideRecord can be helpful for querying and updating records. Let me know if you need a sample script!
Best Regards,
David Baker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 11:56 PM
use below script in your fix scritp:
(function executeFixScript() {
// Define the user field and the employee profile table
var employeeProfileGR = new GlideRecord('x_your_custom_employee_profile'); // Replace with your actual table name
employeeProfileGR.query();
while (employeeProfileGR.next()) {
var user = employeeProfileGR.getValue('user'); // Adjust the field name as needed
if (!user) continue;
var groupList = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', user);
gr.query();
while (gr.next()) {
var groupName = gr.group.name.toString();
groupList.push(groupName);
}
// Join group names with comma and space, or just comma if that's the requirement
var groupListStr = groupList.join(', ');
// Assuming there is a list field or string field to store group names
employeeProfileGR.setValue('group_list_field', groupListStr); // Replace 'group_list_field' with your field name
employeeProfileGR.update();
}
gs.info('Fix script to update user groups in employee profile completed.');
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 12:06 AM
Thanks a lot