Make script dynamic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 10:41 AM
Hi All,
I have a report which fetch all incidents which are opened by or reported by group members of a particular group. Now i would like to make this script dynamic in such a way that user passes the table name in report and based on table name it fetch all incidents, problem or change request which ever table name is passed from end user. ex. javascript:MemberOfCSS('problem').
I am guessing i may have to create a report on task.
Below is my report condition
Below is my script include "MemberOfCSS"
function MemberOfCSS() {
var number = [];
var members = new GlideRecord('sys_user_grmember');
members.addEncodedQuery('group=fcf9daf41b9ab3c0bf1b0d01cd4bcb39');
members.query();
while(members.next())
{
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', members.user.sys_id);
gr.query();
while(gr.next())
{
number.push(gr.number.toString());
}
}
return number;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 11:31 AM
Hi @Nirav ,
Does every table have fields or access to that fields (reference) you are querring in your function?
If so I guess giving your function MemberOfCSS(table) as an parameter and instead of GlideRecord(‘incident’) you will pass table as an argument like this GlideRecord(table).
On client side once user will choose the table you will have to grab that input value (which is table name) and call your function with this inout value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 11:50 AM
Hi IronPotato,
The fields would be different for Problem the field would be "opened_by" and for change request the field would be "requested_by".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2023 12:15 PM - edited 10-24-2023 12:18 PM
@Nirav ,
I would maybe try this;
GlideRecord(“sys_user_grmember” || “field from another table” || “another etc”);
same for the other queries.
also you cant use encodedquery as this is too specific for particular table and the filtering will be different from table to table.