How to setLimit on Related list?

Vijay27
Tera Guru

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

 

1 ACCEPTED SOLUTION

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.

 

Restricting a related list

View solution in original post

8 REPLIES 8

Not working

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.

 

Restricting a related list

Ankur Bawiskar
Tera Patron
Tera Patron

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

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

Thank you but it is not working it shows all records I need only those records which are created from the parent record