The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Jaspal Singh
Mega Patron
Mega Patron

Data management on ServiceNow platform for smooth functioning is must & should be given utmost importance. For instance, there is a workflow that requires Group Manager's approval for fulfillment but the Group does not have Manager data updated. Another one being, a task to be fulfilled & is assigned to a team/group which does not have members. 

In order to be sure that data is in place we can do few checks on regular basis so as to avoid workflow being stuck.

Below are few random checks that can be done by using background scripts or fix scripts. If required same can be used in schedule jobs (to receive mail) with some minor alterations in code. In addition, reports can be created for the same & can be further published as dashboard so as to get a view of everything on single frame.

1. Groups without Members/Users

var gr = new GlideRecord("sys_user_group");
gr.query();
while (gr.next()) {
    var gr1 = new GlideRecord("sys_user_grmember");
    gr1.addQuery("group", gr.sys_id);
    gr1.query();
    if (gr1.getRowCount() == 0) {
        gs.print(gr.getRowCount()); //Just for reference can be commented
        gs.print(gr.name); //Prints Group Name without members
    }
}

 

2. Groups without Managers

var gr = new GlideRecord("sys_user_group");
gr.addEncodedQuery("managerISEMPTY");
gr.query();
while (gr.next()) {
    var gr1 = new GlideRecord("sys_user_grmember");
    gr1.addQuery("group", gr.sys_id);
    gr1.query();
    if (gr1.getRowCount() == 0) {
        gs.print(gr.getRowCount());//Just for reference can be commented
        gs.print(gr.name);//Prints Group Name without Manager
    }
}

 

3. Groups without Type

var gr = new GlideRecord("sys_user_group");
gr.addEncodedQuery("typeISEMPTY");
gr.query();
while (gr.next()) {
    var gr1 = new GlideRecord("sys_user_grmember");
    gr1.addQuery("group", gr.sys_id);
    gr1.query();
    if (gr1.getRowCount() == 0) {
        gs.print(gr.getRowCount());//Just for reference can be commented
        gs.print(gr.name);//Prints Group Name without Group Type
    }
}

 

4. Groups without Parent

var gr = new GlideRecord("sys_user_group");
gr.addEncodedQuery("parentISEMPTY");
gr.query();
while (gr.next()) {
    var gr1 = new GlideRecord("sys_user_grmember");
    gr1.addQuery("group", gr.sys_id);
    gr1.query();
    if (gr1.getRowCount() == 0) {
        gs.print(gr.getRowCount());//Just for reference can be commented
        gs.print(gr.name);//Prints Group Name without Parent
    }
}

 

5. Users not part of any Group

var gr = new GlideRecord('sys_user');
gr.addEncodedQuery("active=true");
gr.query();
while (gr.next()) {
    var gr1 = new GlideRecord('sys_user_grmember');
    gr1.addQuery('user', gr.sys_id);
    gr1.query();
    if (!gr1.next()) {
        gs.print('Count of Users without Group: ' + gr.getRowCount());//Prints Count of Users without Group
        gs.print('Users are :'+gr.name); //Prints User Name
	}
}

Similary, for User without Managers, Department, Business Phone, etc. can be checked for by simply replacing

gr.addEncodedQuery("active=true");

of point 5. with appropriate query so as to get required results. 

 

Hope it helps!

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

1 Comment