Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Remove the type from assignment group if any ticket is not assigned from last 3 month

Rajveer
Tera Expert

Hello Experts,


How to achieve following requirement
If the group has no active members or hasn't been assigned a ticket in 3 months remove the 'Types' from the group and put 'Retired Types' in the Notes field

1 REPLY 1

Its_Azar
Tera Guru
Tera Guru

Hi there @Rajveer 

 

I think you can create a scheduled job that runs periodically to check for groups with no active members or groups that haven't been assigned a ticket in the last 3 months. If such groups are found, the script will update the group record accordingly. lemme pin the scirpt give it a try

var threeMonthsAgo = new GlideDateTime();
threeMonthsAgo.addMonthsUTC(-3);

var groupGR = new GlideRecord('sys_user_group');
groupGR.addQuery('active', true);  
groupGR.query();

while (groupGR.next()) {
    var groupID = groupGR.sys_id;
    var memberGR = new GlideRecord('sys_user_grmember');
    memberGR.addQuery('group', groupID);
    memberGR.addQuery('user.active', true);
    memberGR.query();

    var hasActiveMembers = memberGR.hasNext();

    var taskGR = new GlideRecord('task');
    taskGR.addQuery('assignment_group', groupID);
    taskGR.addQuery('sys_updated_on', '>=', threeMonthsAgo);
    taskGR.query();

    var hasRecentTickets = taskGR.hasNext();
    if (!hasActiveMembers && !hasRecentTickets) {
        groupGR.type = '';  // Remove the 'Types' from the group
        groupGR.u_notes = 'Retired Types';  // Add 'Retired Types' in the Notes field
        groupGR.update();
    }
}

 

If this helps kindly accept the response thanks much.

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG