Article

Automating Group Creation for New Branch Offices or Sites in ServiceNow

Author: Agus Budi Harto, 2025-08-18 10:50:37

In enterprise environments where ServiceNow is integrated with an ERP system as the source of user data, this setup significantly helps ensure that job titles (user title fields) remain accurate and up to date. This is true even if the synchronization frequency between the ServiceNow user table and the ERP employee table is limited—since higher sync frequency can consume substantial network bandwidth.

However, a new challenge arises when employees begin submitting tickets, but the appropriate assignment groups do not yet exist. While manually creating one or two groups is manageable, the situation becomes more complex when a large number of groups need to be created due to the opening of new branch offices or sites. This can be time-consuming, and ticket submissions from employees cannot be paused while waiting for group setup.

The Solution: Automate Group Creation

To address this, the only scalable solution is to automatically create assignment groups based on specific logic. Here's a practical approach:

  1. Group Name Prefix: Use the branch office or site name as the prefix (e.g., the first 4 letters).
  2. Separator: Use a dash (-) to separate the prefix from the rest of the name.
  3. Job Title Suffix: Append the employee's job title to the group name. This helps avoid duplicate group creation.
  4. Title Filtering: Only include job titles that are likely to act as approvers or fulfillers:
    • Titles containing "Head" are considered potential approvers.
    • Titles containing "Service Desk" are considered potential fulfillers.

This logic ensures that only relevant groups are created, reducing clutter and improving ticket routing efficiency.

Example Script

Below is a sample script that can be used to:

  • Identify existing groups for a specific branch office.
  • Detect groups that should no longer be associated with employees who have transferred to new roles or locations.
var PM_Check = Class.create();
PM_Check.prototype = Object.extendsObject(AbstractAjaxProcessor, {
  checkSiteGroup: function(){
gs.info("Need to add or not:");
var siteToCheck = "ABCD";
var site = this.getLocation(siteToCheck);
var limit = "titleLIKEDEPT. HEAD^ORtitleLIKEEXPERT COORDINATOR^ORtitleLIKEMANAGER^ORtitleLIKEIT SECT. HEAD^ORtitleLIKEIT Service Desk";
var gr = new GlideRecord("sys_user");
gr.addQuery("location",site);
gr.addEncodedQuery(limit);
gr.orderBy("title");
gr.query();
var title = "";
var foundGrp = [];
var notFoundGrp = [];
while(gr.next()){
if (title!=gr.title.getDisplayValue()){
//check in existing group
var grpName = siteToCheck + " - " + gr.getDisplayValue("title");
var gr1 = new GlideRecord("sys_user_group");
gr1.addQuery("name",grpName);
gr1.query();
if(gr1.next()){
foundGrp.push(grpName);
}else{
notFoundGrp.push(grpName);
//inserting code to add group
}
}
title=gr.title.getDisplayValue();
}
var uniqueSortedFoundGrp = Array.from(new Set(foundGrp)).sort();
var uniqueSortedNotFoundGrp = Array.from(new Set(notFoundGrp)).sort();
uniqueSortedFoundGrp.forEach(function(item, index) {
gs.info("Found:" + item);
});
uniqueSortedNotFoundGrp.forEach(function(item, index) {
gs.info("NOT Found:" + item);
});
gs.info("");
gs.info("Whether to remove:");
var toRemove = [];
var gr2 = new GlideRecord("sys_user");
gr2.addQuery("location",site);
gr2.query();
while(gr2.next()){
var userid = gr2.sys_id.toString();
var gr3 = new GlideRecord("sys_user_grmember");
gr3.addQuery("user",userid);
gr3.query();
while(gr3.next()){
var esite = gr3.getDisplayValue("group").substring(0,4);
if(esite!=siteToCheck){
toRemove.push(gr3.getDisplayValue("group"));
}
}
}
var uniqueSortedToRemove = Array.from(new Set(toRemove)).sort();
uniqueSortedToRemove.forEach(function(item, index) {
gs.info("To Remove:" + item);
});
    },
    type: 'PM_CloningSLA'
});

Background script:

var helper = new PM_Check();
helper.checkSiteGroup();

Note: This script is a simplified example. In a real ServiceNow environment, you'd use server-side scripting (e.g., Business Rules, Script Includes, Flow Designer or background script above) to implement this logic securely and efficiently.




LinkedIn

Tags: Opinion Servicenow

193 reviews


Add comment