Is there any way to run script include in report?

Yash47
Tera Contributor

I have written a script include 

function P2_Count() {

    gs.log("Inside Script include");
    var str = [];

    count = new GlideAggregate('incident');
    count.addEncodedQuery('assignment_group=6351d485db4e67803629f7051d9619e9^priority=2^active=true'); #for particular group's incident
    count.addAggregate('COUNT', 'cmdb_ci');
    count.groupBy('cmdb_ci');
    //count.orderByAggregate('COUNT', 'cmdb_ci');
    count.addHaving('COUNT', '>', 5);
    count.query();
    while (count.next()) {
        str.push(count.cmdb_ci.toString());
    }
    gs.log(str);
    return str;
}

 

and , called this script include in report as;

javascript: P2_Count();

I am getting results but not getting any logs as I have entered logs in between the code
And also Properly not working the line 

count.addHaving('COUNT', '>', 5);

getting random count in report

 

Please Find the Attachments and Please help me out...

Can we call script include from any report?

9 REPLIES 9

Jaspal Singh
Mega Patron
Mega Patron

Hi Yash,

There are few syntax issues with script. Can you share script instead of screenshot.

Hello Jaspal,

Thanks for reply ,

var Yash_test = Class.create();
Yash_test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    P2_Count: function() {
        gs.info("Inside Script Yash test includeeeeeee");
        var str = [];
        count = new GlideAggregate('incident');
        count.addEncodedQuery('assignment_group=6351d485db4e67803629f7051d9619e9^priority=2^active=true');
        count.addAggregate('COUNT', 'cmdb_ci');
        count.groupBy('cmdb_ci');
        //count.orderByAggregate('COUNT', 'cmdb_ci');
        count.addHaving('COUNT', '>', 7);
        count.query();
        while (count.next()) {
            str.push(count.cmdb_ci.toString());
        }
        gs.info(str);
        return str;
    },

    type: 'Yash_test'
});

 

***Above is the script***

 

javascript:new Yash_test().P2_Count();

palanikumar
Mega Sage

Hi,

From screenshot I can see that your script returns 4 sys_id as highlighted in the below screenshot. Confirm whether they are the expected output from the script.

And then based on your condition it filters tickets created today (after yesterday means it skips yesterday). If you want to consider yesterday ticket as well then you need to change operator to "Created" "at or after" "Yesterday".

Make sure DC CI field has the sys_ids returned by the script

 

Thank you,
Palani

Hello Palanikumar,

Thanks for reply ,

var Yash_test = Class.create();
Yash_test.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    P2_Count: function() {
        gs.info("Inside Script Yash test includeeeeeee");
        var str = [];
        count = new GlideAggregate('incident');
        count.addEncodedQuery('assignment_group=6351d485db4e67803629f7051d9619e9^priority=2^active=true');
        count.addAggregate('COUNT', 'cmdb_ci');
        count.groupBy('cmdb_ci');
        //count.orderByAggregate('COUNT', 'cmdb_ci');
        count.addHaving('COUNT', '>', 7);
        count.query();
        while (count.next()) {
            str.push(count.cmdb_ci.toString());
        }
        gs.info(str);
        return str;
    },

    type: 'Yash_test'
});

 

***Above is the script***

 

javascript:new Yash_test().P2_Count();

Hi,

I hope your previous script worked as well. Can you confirm whether you are looking for records created today or do you need any other condition in report?

As per your earlier screenshot you added condition to filter tickets created today. Refer the image I shared in previous message. Remove or update the condition based on earlier message and confirm whether it is working fine

Thank you,
Palani