Selecting active user from Group and add it to Assigned to field in incident form in ATF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 08:43 AM
Hi,
I have few ATF tests where I need to select active member from Group and then add it to Assigned to Field in the Incident, Problem and Change request before submitting the forms. I am new to ServiceNow scripting. Looking for some help to achieve this using the server-side script.
Thank you
Rajeshwari H P
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 11:34 AM
Hi @Rajeshwari H P ,
Please use below code as reference -
function selectActiveMemberAndAddToAssignedTo(group_id, assigned_to_field) {
// Get the list of active members in the group.
var gL = new GlideRecord('sys_user');
gL.addQuery('group', group_id);
gL.addQuery('active', true);
gL.query();
// If there are no active members in the group, return.
if (gL.getRowCount() == 0) {
return;
}
// Select the first active member in the list.
if (gL.next()) {
// Set the value of the Assigned to field in the target table
var targetGR = new GlideRecord('<target_table_name>');
targetGR.get('<target_record_sys_id>'); // Replace with the sys_id of the record you want to update
targetGR.setValue(assigned_to_field, gL.sys_id);
targetGR.update();
}
}
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 01:44 AM
I got the perfect answer of your question:
Regards
Shaqeel
***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
***********************************************************************************************************************
Regards
Shaqeel