Script Include in Reporting Filter not working, but hard coded values work

Daniel Gleason
Giga Expert

Hello,

 

I am trying to generate a report dynamically, ie by using a script include in the filter condition. Below is the script include. Please see the two attached pictures for the report.

 

What is confusing to me is that the sysIDs I need, when hardcoded into the filter condition, generate data in the report, but when I use the script include by putting it in the filter condition, despite the fact that the "filter breadcrumbs" recognizes the sysIDs returned by the script include (these are the same sysIDs as the hardcoded ones), no data in the report is generated. See pictures for a visual! I am using "is one of" for the filter condition. 

 

Here is the script include (in scoped app): 

 

Client callable: true

Accessible from all application scopes 

 

 

 

 

 

 

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

    getLatestAppPeriods: function() {
        var app_period_array = [];
		var applications_no_duplicates = [];

        var appPeriods = new GlideRecord('xxxxxxxxxxxxxx');
        appPeriods.orderByDesc('end_date'); // sort by end_date (descending order)
        appPeriods.query();


        while (appPeriods.next()) {// put only the most recent, non-duplicate application app period sysIds into an array 

            if (applications_no_duplicates.indexOf(appPeriods.getValue('application')) == -1) { 
				
                applications_no_duplicates.push(appPeriods.getValue('application'));

                app_period_array.push(appPeriods.getUniqueValue());
            }
        }
        return app_period_array.toString();
    },


    type: 'DaitoReportUtils'
});

 

 

 

 

 

 

The report is in the same scoped app. 

 

Thanks,
Dan 

 

 

1 ACCEPTED SOLUTION

The solution was actually I had to call specify the scope prefix in the script include when I called it! Thank you, though!

View solution in original post

3 REPLIES 3

Tony Chatfield1
Kilo Patron

Hi, your code shows you have created a script-include that extends global.AbstractAjaxProcessor

But the script-include call is a server (possibly scoped) and not a client called ‘ajax type’ script.

Have you added any debugging to confirm that the script is running and that expected results are being returned?
Also ‘appPeriods.orderByDesc('end_date')’ seems pointless to me as it has no impact on your results, can you clarify the intention?

The solution was actually I had to call specify the scope prefix in the script include when I called it! Thank you, though!

Hi Daniel,

 

I have come across a similar situation and below are the screen shots of the script include which is getting called and the logic . Even I am not able to see the data although it is present. Can you please help?

 

chatsaurav19_0-1736933489398.png

 

chatsaurav19_1-1736933509095.png

 

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

    getlastWorkingDay: function() {
        var today = new GlideDateTime();
        var dayOfWeek = today.getDayOfWeek(); // Returns 1 (Sunday) to 7 (Saturday)
        var lastWorkingDay = new GlideDateTime(today);

        // If today is Monday, subtract 3 days (i.e., Friday)
        if (dayOfWeek == 1) {
            lastWorkingDay.addDaysUTC(-3);
        }
        // If today is Sunday, subtract 2 days (i.e., Friday)
        else if (dayOfWeek == 7) {
            lastWorkingDay.addDaysUTC(-2);
        }
        // For any other weekday (Tuesday to Saturday), subtract 1 day
        else {
            lastWorkingDay.addDaysUTC(-1);
        }

        var date1 = '2025-01-15';
        //var sysId = gs.getProperty('mdm.china.catItem');

        var arr = [];
        var gr1 = new GlideRecord('sc_req_item');
        gr1.addQuery('cat_item', 'b29ac221975bd5d0e32a3e771153afd6');
        gr1.query();
        while (gr1.next()) {
            var gdt2 = new GlideDateTime(gr1.closed_at);
            var date2 = gdt2.getDate();
            if (date2 == date1) {
                gs.info(date2 + " " + date1);
                arr.push(gr1.getUniqueValue().toString());
                gs.info(gr1.number);
            }
        }
        return arr;
    },

    type: 'getLastWorkingDay'
});

Regards,

Saurabh