How to use script include function in report

VallabhiAgr
Tera 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

 

1 ACCEPTED SOLUTION

@VallabhiAgr 

did you run your script include in background and you are getting result i.e. sysIds?

also Sandbox checkbox if not on Form, then from list make it true

AnkurBawiskar_0-1765372838836.png

Configuring Script sandbox property 

💡 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

View solution in original post

6 REPLIES 6

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.