- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2019 11:56 PM
Hi Folks,
I want to show only 20 records that are opened for the user.
function refineQuery(current, parent) {
var qc = current.addQuery("opened_for", parent.opened_for);
current.addQuery("sys_id", "!=", parent.getUniqueValue());
current.orderByDesc("sys_created_on");
})(current, parent);
Regards,
Vijay
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 12:08 AM
try to do glide record and then use current object .
sample code:
var inc = new GlideRecord('incident');
inc.addQuery('caller_id', parent.caller_id);
inc.orderByDesc('sys_created_on');
inc.setLimit(10);
inc.query();
var ids = [];
while (inc.next()) {
ids.push('' + inc.sys_id);
}
current.addQuery('sys_id', ids);
just modify this script based on your need. give a try.
Kindly refer the below thread for another sample code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 12:04 AM
Not working

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 12:08 AM
try to do glide record and then use current object .
sample code:
var inc = new GlideRecord('incident');
inc.addQuery('caller_id', parent.caller_id);
inc.orderByDesc('sys_created_on');
inc.setLimit(10);
inc.query();
var ids = [];
while (inc.next()) {
ids.push('' + inc.sys_id);
}
current.addQuery('sys_id', ids);
just modify this script based on your need. give a try.
Kindly refer the below thread for another sample code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 12:13 AM
Hi Vijay,
setLimit() may not work in related list query; try this code
ensure table name in query is correct; I have used incident; you take yours table name
function refineQuery(current, parent) {
var sysIdArray = [];
var gr = new GlideRecord('incident');
gr.addQuery('opened_for', parent.opened_for);
gr.addQuery('sys_id', '!=', parent.getUniqueValue());
gr.orderByDesc('sys_created_on');
gr.setLimit(20);
gr.query();
while gr.next())
{
sysIdArray.push(gr.getValue('sys_id'));
}
current.addQuery('sys_id','IN',sysIdArray.toString());
})(current, parent);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2020 03:58 AM
Thank you but it is not working it shows all records I need only those records which are created from the parent record