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

Pratiksha Kalam
Kilo Sage

Hi Vijay,

Go through below link will help you,

https://community.servicenow.com/community?id=community_question&sys_id=972387e1dbd8dbc01dcaf3231f96...

If my reply helps you at all, I’d really appreciate it if you click the Helpful button and if my reply is the answer you were looking for, it would be awesome if you could click both the Helpful and Accepted Solution buttons!

 

Regards,

Pratiksha

Omkar Mone
Mega Sage

Hi 

Can you try this way - 

var count = 20;

current.addQuery("opened_for", parent.opened_for);
current.addQuery("sys_id", "!=", parent.getUniqueValue());
current.orderByDesc("sys_created_on");

current.setLimit(count);

 

Regards,

Omkar Mone

Hi 

Can you try with removing all and just keeping - 

current.setLimit(20);

Harsh Vardhan
Giga Patron

use setLimit()

 

Updated Code:

 

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.setLimit(20);

})(current, parent);