Report script less than 5 tasks closed per user (tasktable)

rosti
Tera Contributor

Hey all

I have a customer who only wants to see a list report that gives only users who have closed less than 5 tasks over 30 days (All Tasks)

I see that there are limitations in the creation of a report and would like to hear from you experts how a script could be used for this and which I call via the report.

Thank you for your support.

2 ACCEPTED SOLUTIONS

Hi @rosti ,
The issue is in the encoded query line in script include.
The encodedQuery should be link this:

SonuParab_0-1692540020478.png

 

and I have observed that in your script line there is javascript&colon.


gr.addEncodedQuery("closed_atONLast 30 days@javascript:gs.beginningOfLast30Days()@javascript:gs.endOfLast30Days()");
gr.addAggregate('COUNT', 'closed_by');


could you please make these changes.
this will work.

 

View solution in original post

Hi @rosti ,
I have updated the script include If condition to check the fulfiller role. rest of the script is as it is.

  if (gr.getAggregate('COUNT', 'closed_by') < 5) { // here we are checking aggregate count

                var closesby = gr.closed_by.toString(); //Get closed by user i.e.user sys_id
                var role = "itil"; // Here  you can pass role called IT Service Management Professional. 
                var checkrole = gs.getUser().getUserByID(closesby).hasRole(role);// ckecking closed by user having fulfiller role
                if (checkrole) { // if true then and then only push sys_if into array.
                    usersys.push('' + closesby);
                }
            }

 

SonuParab_0-1692551592376.png

 

View solution in original post

23 REPLIES 23

Hi @rosti 

Check this KB, and let me know if you have any difficulties using this.

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0746219

 

Thanks,
Anvesh

rosti
Tera Contributor

Hi again 

Trying to run this script but didn't get it to work properly ( new in to this )

Can you help out

 

Thanxs  

 

var getTasks = Class.create();
getTasks.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getTasks: function(){
 
var gr = new GlideAggregate('task');
gr.addEncodedQuery('closed_atONLast 30 days@javascript&colon;gs.beginningOfLast30Days()@javascript&colon;gs.endOfLast30Days()');
 
gr.addAggregate('COUNT','assigned_to');
 
gr.query();
 
var users = [];
 
while(gr.next()){
 
if(gr.getAggregate('COUNT','assigned_to') < 5){
 
users.push(gr.assigned_to);
 
}
}
 
return users.join(',');
},
 
type: 'getTasks'
 
});

 

rosti
Tera Contributor

Using task table for the report wit sys ID is javascript&colon;getTasks();

Sonu Parab
Mega Sage
Mega Sage

Hello @rosti ,

 

To achieve your requirement follow below step.

 

Step 1 - Create one script include. The  script will be Client Callable And All Application Scope accessible.

the script as follows:

var fetchusers = Class.create();
fetchusers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUsers: function() {


        var usersys = [];
        var gr = new GlideAggregate("task");
        gr.addEncodedQuery("closed_atONLast 30 days@javascript&colon;gs.beginningOfLast30Days()@javascript&colon;gs.endOfLast30Days()");
        gr.addAggregate('COUNT', 'closed_by');
        gr.query();
        while (gr.next()) {

            if (gr.getAggregate('COUNT', 'closed_by') < 5) {
                // gs.info(gr.number);
                var closesby = gr.closed_by.toString();
                usersys.push('' + closesby);
            }
        }
        // gs.info(usersys);
        return usersys;

    },

    type: 'fetchusers'
});

 

Step 2 - 
Create Report on the User table.

and Add filter as follows;
Sys ID is one of javascript&colon; new fetchusers().getUsers();
Here fetchusers() is a script include name. and getUsers() is a function in a script include.

 

SonuParab_0-1692533359177.png

 

If my response successfully addresses your query, I kindly request you to consider marking it as the accepted solution. Doing so can be beneficial for others who might have a similar concern.

Thank you!

 

rosti
Tera Contributor

Thanxs for all help so far really appriciated

Also is it possible to have condition that the user is a Fullfiller in the script ?

 

//rosti