Need to call script include in reporting.

Pragati4
Tera Contributor

Hi All

I have a requirement in which i want to get report of all the cases who's assignment group is part of "report group".

"report group" is a field which i have created in my user form in which we can add n number of groups.

 I know we can achieve this using script include then calling that function using java script but that is knot working i dont know why.

i have written below code but this is not working

var getGroup = Class.create();
getGroup.prototype = {
initialize: function() {
},
getreportgroup: function(){
var group ='';
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',current.sys_id);
user.query();
while(user.next()){
group = user.u_report_group.toString();
}
group = 'sys_idIN' + group;
gs.log('testing'+ group);
return group;

},
type: 'getGroup'
};

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Pragati,

You should send an array, updated script here

var group =[];
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',current.sys_id);
user.query();
while(user.next()){
group.push(user.u_report_group.toString());
}
gs.log('testing'+ group);
return 'sys_idIN' + group;
},

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

In report i  m calling this function as:

assignment group is javascript:new getGroup().getreportgroup();

but getting all the ticket detail in which assignment group is empty.

I do not know what is wrong in this.

 

Hi Pragati,

current object won't work here. I believe what you want is groups based on logged in user so use gs.getUserID()

Updated code:

user.addQuery('sys_id',gs.getUserID());

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur

Thankyou for your response.

This is also not working its giving me all the record in which assignment group is empty.

script:

var getGroup = Class.create();
getGroup.prototype = {
initialize: function() {
},
getreportgroup: function(){
var group =[];
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',gs.getUserID());
user.query();
while(user.next()){
group.push(user.u_report_group.toString());
}
gs.log('testing'+ group);
return 'sys_idIN' + group;
},
type: 'getGroup'
};

Regards,

Pragati