call script include in a report condition

kunal16
Tera Expert

Hi All,

I have a script include which returns the sys_id of RITMs created on this month. I am trying to call that script include in the condition for a report like - Sys ID is one of javascript: new myRITM().thisMonthRITMs()

But I am not able to fetch any record in my report.

P.S. - I know that this can be done using the filter Created on This month, but I want to do it with a script include

Here is my script include:

Name: myRITM

Client callable: FALSE

Script:

var myRITM = Class.create();

myRITM.prototype = {

  initialize: function() {

  },

  thisMonthRITMs : function()

  {

            var arr = [];

            var querystring = 'active=true^sys_created_onONThis month@javascript:gs.beginningOfThisMonth()@javascript:gs.endOfThisMonth()';

            var ritm = new GlideRecord('sc_req_item');

            ritm.addEncodedQuery(querystring);

            ritm.query();

            while (ritm.next())

            {

                      arr.push(ritm.sys_id);

            }

            gs.log('@@ ' + arr);

            return arr;

  },

  type: 'myRITM'

};

Any help will be appreciated.

Thanks in advance!!

7 REPLIES 7

Dominik Simunek
Tera Guru

Hi Kunal,



I believe you need to make the script include Client Callable to execute it from URL / condition builder. Also as already mentioned, you need to add the sys_ids to array either via ritm.getValue('sys_id') or ritm.sys_id.toString() as otherwise you would get only the last RITM.



One note - gs.log will not work in such client callable script include so don't be surprised that you won't see your logged message in the system logs.


This is the code that is working for me (tested on my DEV instance as admin). Script Include must be client callable.



var MyRITM = Class.create();


MyRITM.prototype = {



  /**


  * Returns array of sys_ids of Requested Items created this month.


  *


  * @return {Array} - sys_ids of RITMs created this month.


  */


  thisMonthRITMs: function() {


        var ritmArray = [];


        var querystring = 'active=true^sys_created_onONThis month@javascript:gs.beginningOfThisMonth()@javascript:gs.endOfThisMonth()';



        var ritmGR = new GlideRecord('sc_req_item');


        ritmGR.addEncodedQuery(querystring);


        ritmGR.query();


        while (ritmGR.next()) {


              ritmArray.push(ritmGR.getValue('sys_id'));


        }



        return ritmArray;


  },



  type: 'MyRITM'


};



and then you can call it as:


Capture.PNG


Hope this works for you as well.


hi Dominik,

I have similar requirement could you please look the below link once and suggest me,

https://community.servicenow.com/community?id=community_question&sys_id=1f49fa41dbfc7fc4d58ea345ca96...