Do you know how to get List of records on a table using script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 05:33 AM
Do you know how to get List of records on a table where we have to check some conditions across various tables in ServiceNow whereas inbuilt table filter is not sufficient?
Dynamic Filter using script include will help here. If we have not created Dynamic filter but we have a script include with the function where we are doing all the checks from various tables and returning the numbers of all required records Then how to build an URL to get those records from a table.
Use Case: User need a filter on incident table where he will get all the incidents in which user or user's delegate is to be the caller
Create a script include:
var myanddelegateduserrequests = Class.create();
myanddelegateduserrequests.prototype = Object.extendsObject(AbstractAjaxProcessor, {
myandmydelegatedusersrequests:function()
{
var b=[];
var t = gs.getUserID()
b.push(t.toString())
var gr = new GlideRecord('sys_user_delegate')
gr.addQuery('user',gs.getUserID())
gr.query();
while(gr.next())
{
b.push(gr.delegate.toString())
}
var m=[];
for(var i=0;i<b.length;i++)
{
var kr = new GlideRecord('incident');
kr.addQuery('caller_id',b[i])
kr.query();
while(kr.next())
{
m.push(kr.number.toString())
}
}
gs.addInfoMessage(m.toString())
return m.toString();
},
type: 'myanddelegateduserrequests'
});
Query in the URL:
sysparm_query=numberINjavascript: new global.myanddelegateduserrequests().myandmydelegatedusersrequests()
Kindly click on helpful if it helps