Calling Script include in a report

SmitP
Tera Contributor

I am working on a request for a dashboard where users can see ticket activities for assigned to and assignment group in a simple view rather than opening the ticket and scrolling through it.

 

They would like to see the old and new assigned to and assignment group values in different columns (4 columns total)
I tried creating a script include and calling it from the report, but it's not fetching any values. 

Here's the Script include 

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

    getAuditChanges: function() {
        var result = {};

        // Step 1: Get 20 unique ticket Sys IDs with changes to assigned_to or assignment_group
        var ticketIds = [];
        var grAudit = new GlideAggregate('sys_audit');
        grAudit.addEncodedQuery('fieldnameINassigned_to,assignment_group');
        grAudit.groupBy('documentkey');
        grAudit.orderByDESC('sys_created_on');
        grAudit.setLimit(20);
        grAudit.query();
        while (grAudit.next()) {
            ticketIds.push(grAudit.getValue('documentkey'));
        }

        // Step 2: Query sys_audit for changes to those tickets
        if (ticketIds.length === 0) return result;

        var gr = new GlideRecord('sys_audit');
        gr.addQuery('documentkey', 'IN', ticketIds.join(','));
        gr.addQuery('fieldname', 'IN', 'assigned_to,assignment_group');
        gr.orderBy('documentkey');
        gr.orderByDESC('sys_created_on');
        gr.query();

        while (gr.next()) {
            var ticket = gr.getValue('documentkey');
            if (!result[ticket]) {
                result[ticket] = [];
            }

            result[ticket].push({
                field: gr.getValue('fieldname'),
                old_value: gr.getDisplayValue('oldvalue'),
                new_value: gr.getDisplayValue('newvalue'),
                changed_on: gr.getDisplayValue('sys_created_on')
            });
        }

        return result;
    },

    type: 'AuditChangeFetcher'
};

 

how I am calling it: 

javascript:new scriptincludename().AuditChangeFetcher()
1 REPLY 1

YaswanthKurre
Giga Guru

Hi Smit,

 

You should call the script include properly, follow the code snippet below:

javascript: new AuditChangeFetcher().getAuditChanges(); // if this is in different scope , use api name in pace of script include name

 

If this resolved your issue, mark this as correct.