The CreatorCon Call for Content is officially open! Get started here.

Selecting active user from Group and add it to Assigned to field in incident form in ATF

Rajeshwari H P
Tera Contributor

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

2 REPLIES 2

Tushar
Kilo Sage
Kilo Sage

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

Shaqeel
Mega Sage
Mega Sage

Hi @Rajeshwari H P 

 

I got the perfect answer of your question:

https://www.servicenow.com/community/developer-articles/atf-custom-step-configuration2-get-an-active...

 

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