Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Limit the number of Records display on Report ?

shashankverma05
Tera Contributor

I have created a report, but on home page its showing the n number of records , but i want it show only the first 5 records.

i have restrict the record form the list layout, but it was applicable to all of the table.

is there any method so we can restrict the number of record to 5 only.

 

find_real_file.png

 

Thanks

8 REPLIES 8

Anurag Tripathi
Mega Patron
Mega Patron

Hi Shashank,



Apart from the first 5 records, is there any other condition also working on this report?


-Anurag

its should show the latest 5 record and report runs in every 30 min.


in that case apply a filter on the replort like this



<field> <is> <javascript: new my_script_include().runReport() >


here field is any string field



now on your script include you can write your own Glide Record to return any thing and you can limit it to 5



What i did was this:



report filter



<number><is one of> <javascript: new my_script_include().runReport()>



script include code



runReport: function()


  {


  var x=[];


  var gr = new GlideRecord("pm_project");


  gr.addQuery("name", "test");


  gr.setLimit('5');


  gr.query();


  while (gr.next()) {


      x.push(gr.getValue('number'));


  }


  return x;


  },


-Anurag

Hi Anurag,



i tried with your solution, My script include is working fine.


But however when i add it to the filter condition of the Report.


No records are being displayed in the report.



Could you please suggest what could be the issue



javascript:   new my_script_include().runReport();



script include:


var my_script_include = Class.create();


my_script_include.prototype = {


      initialize: function() {


      },


  runReport : function()


  {


  var x=[];


  var gr = new GlideRecord("change_request");


  gr.addQuery("active", "true");


  gr.setLimit('5');


  gr.query();


  while (gr.next()) {


      x.push(gr.getValue('number'));


  }


  return x;


  },


      type: 'my_script_include'


};