call script include in a report condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2017 02:47 AM
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2017 07:03 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2017 07:14 AM
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:
Hope this works for you as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2019 11:47 PM
hi Dominik,
I have similar requirement could you please look the below link once and suggest me,