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.

How to use script include function in report

VallabhiAgr
Giga Contributor

script include :

var BlankRequestChecker = Class.create();
BlankRequestChecker.prototype = {
    initialize: function() {},

 

    getBlankRequestList: function() {
        var blankRequestSysIDs = [];
        var req = new GlideRecord('sc_request');
        req.addQuery('active'true);
        req.query();

 

        while (req.next()) {

 

            var ritm = new GlideRecord('sc_req_item');
            ritm.addQuery('request', req.sys_id);
            ritm.query();
            if (ritm.hasNext()) continue;

 

            var approval = new GlideRecord('sysapproval_approver');
            approval.addQuery('sysapproval', req.sys_id);
            approval.addQuery('state''requested');
            approval.query();
            if (approval.hasNext()) continue;

 

            var task = new GlideRecord('sc_task');
            task.addQuery('request', req.sys_id);
            task.addQuery('active'true);
            task.query();
            if (task.hasNext()) continue;

 

            blankRequestSysIDs.push(req.sys_id.toString());
        }

 

        return blankRequestSysIDs;    
    },

 

    type: 'BlankRequestChecker'
};

This is how I call it in report, it is showing error 
VallabhiAgr_0-1765363840276.png

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@VallabhiAgr 

your script include should be client callable then only it can be called from report filter condition

If you have created the Script Include in ServiceNow version "Washington" and above make sure, you have checked the "Sandbox enabled" Checkbox.

AnkurBawiskar_0-1765365201209.png

 

var BlankRequestChecker = Class.create();
BlankRequestChecker.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getBlankRequestList: function() {
        var blankRequestSysIDs = [];
        var req = new GlideRecord('sc_request');
        req.addQuery('active', true);
        req.query();
        while (req.next()) {

            var ritm = new GlideRecord('sc_req_item');
            ritm.addQuery('request', req.sys_id);
            ritm.query();
            if (ritm.hasNext()) continue;

            var approval = new GlideRecord('sysapproval_approver');
            approval.addQuery('sysapproval', req.sys_id);
            approval.addQuery('state', 'requested');
            approval.query();
            if (approval.hasNext()) continue;

            var task = new GlideRecord('sc_task');
            task.addQuery('request', req.sys_id);
            task.addQuery('active', true);
            task.query();
            if (task.hasNext()) continue;

            blankRequestSysIDs.push(req.sys_id.toString());
        }
        return blankRequestSysIDs;
    },

    type: 'BlankRequestChecker'
});

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

VallabhiAgr_0-1765365506731.png

its already client callable still getting the error

@VallabhiAgr 

client callable script include should not have initialize() method

Please remove that and copy my script

Also ensure about this point

If you have created the Script Include in ServiceNow version "Washington" and above make sure, you have checked the "Sandbox enabled" Checkbox.

AnkurBawiskar_0-1765367966164.png

 

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

VallabhiAgr_0-1765369190031.png

I have used your script still getting the same error and I am using Yokhlama version there is not option for sandbox.