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.

Report for priority of incidents

siddharth26
Tera Guru

Hi All,

 

I have a requirement to pull the details of the incident whose priority is downgraded.

 

for example :

if the priority downgraded from P1 to P2 , P3 to P4, or P1 to P4.

so i need the details of those incidents whose priority had been changed and downgraded,

 

could you please provide any suggestion on this 

thanks

sid

5 REPLIES 5

Maddysunil
Kilo Sage

@siddharth26 

I think you can write a script include to get the required incident and return the sysids, And call the script include in report filter condition like sysid in new scriptInclude().functionName()

Sample Script include:

 

var downgradedIncidentSysIds = []; // Array to store sys_ids of downgraded incidents

    // Query incidents where priority has been downgraded
    var gr = new GlideRecord('incident');
    gr.addEncodedQuery('active=true^priorityIN1,2,3,4'); // Filter active incidents with specified priorities
    gr.query();
    while (gr.next()) {
        var oldPriority = gr.priority.getPreviousValue(); // Get the previous priority value
        var newPriority = gr.priority.getValue(); // Get the current priority value

        // Check if the priority has been downgraded
        if (newPriority > oldPriority) {
            // Store the sys_id of the downgraded incident
            downgradedIncidentSysIds.push(gr.sys_id);
        }
    }

    // Return the array containing sys_ids of downgraded incidents
    return downgradedIncidentSysIds;
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Hi @siddharth26 ,

 

There is nothing such called getPreviousValue() function. Can you justify why script include ?


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Vishwa Pandya19
Mega Sage

AndersBGS
Tera Patron
Tera Patron

Hi @siddharth26 ,

 

This can be captured by a metric definition for the priority field, but not that this solution requires 3 metrics (one for each priority).

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/