I need to create UI action on the Incident List in service operation Workspace

Deepika61
Tera Contributor

Hi All,

Actually i have requirement that need to create  a Ui action "Next Incident" on the "Unassigned i group list"

  • When I click on the Next Incident button from the "Unassigned in my Group" Incident List in the Service Operations Workspace,
  • The next valid incident is assigned to me, following the logic of:
    • The Incident in the list which has the least remaining business time on it's In Progress response SLA,
    • If no Incidents have In Progress Response SLAs, then the Incident in the list which has the least remaining business time on it's Resolution SLA.

Please help me to achieve this

 

Thanks

Deepika

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Deepika61 

sorry your requirement is not clear.

can you share what did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

Actually in the Sow , in incident list "Unassigned i group list", i need a ui action called "Next Incident"

Deepika61_0-1741058612257.png

when i click on that ui action, its needs to assign the incident based on above criteria which i mentioned 

 

Thanks

Deepika

@Deepika61 

you can create a list banner button on Incident and have logic within it for those 2 points.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hemant Ch
Tera Expert

Hi Deepika 

Create a ui action and write below code in workspace 

function nextIncident() {
    // Get current user
    var currentUser = gs.getUserID();
    
    // Get user's groups
    var userGroups = [];
    var groupGR = new GlideRecord('sys_user_grmember');
    groupGR.addQuery('user', currentUser);
    groupGR.query();
    while (groupGR.next()) {
        userGroups.push(groupGR.group.toString());
    }

    // Query unassigned incidents in user's groups
    var incGr = new GlideRecord('incident');
    incGr.addQuery('assignment_group', 'IN', userGroups.join(','));
    incGr.addNullQuery('assigned_to');
    incGr.addQuery('state', '1'); // New state
    incGr.query();

    var leastTimeIncident = null;
    var leastRemainingTime = -1;

    // First check for Response SLA
    while (incGr.next()) {
        var taskSLA = new TaskSLA(incGr);
        var responseSLA = taskSLA.findSLA('response_time');
        
        if (responseSLA && responseSLA.business_time_left > 0) {
            if (leastRemainingTime == -1 || responseSLA.business_time_left < leastRemainingTime) {
                leastRemainingTime = responseSLA.business_time_left;
                leastTimeIncident = incGr;
            }
        }
    }

    // If no incident found with Response SLA, check Resolution SLA
    if (!leastTimeIncident) {
        incGr.query();
        while (incGr.next()) {
            var taskSLA = new TaskSLA(incGr);
            var resolutionSLA = taskSLA.findSLA('resolution_time');
            
            if (resolutionSLA && resolutionSLA.business_time_left > 0) {
                if (leastRemainingTime == -1 || resolutionSLA.business_time_left < leastRemainingTime) {
                    leastRemainingTime = resolutionSLA.business_time_left;
                    leastTimeIncident = incGr;
                }
            }
        }
    }

    // Assign incident if found
    if (leastTimeIncident) {
        leastTimeIncident.assigned_to = currentUser;
        leastTimeIncident.state = 2; // In Progress
        leastTimeIncident.update();
        
        gs.addInfoMessage('Incident ' + leastTimeIncident.number + ' has been assigned to you.');
        action.setRedirectURL(current);
    } else {
        gs.addInfoMessage('No unassigned incidents found in your groups.');
    }
}

nextIncident();