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.

Random Request Report

kanielb1
Mega Expert

Is it possible to create a report that pulls random cases/requests based on the assigned to?

Or how could I create a page or module that would pull a random list of records based on the assigned to in a scoped application?

1 ACCEPTED SOLUTION

kanielb1
Mega Expert

I found the following solution on another community post.


Create a UI Page:


[CODE]


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<script>


      window.onload = function() {


  randomCase();


};


      </script>    


</j:jelly>


[/CODE]



Client Script:


[CODE]


function randomCase(){


      var caseList = [];


      var rec = new GlideRecord('table');


      rec.addQuery('active', true);


      rec.addQuery('investigator', 'IN', 'Name1,Name2,Name3,Name4');


      rec.query();



      while (rec.next()){


              caseList.push(rec.getValue('number'));


      }


   


      var random = Math.floor((Math.random() * caseList.length));


      var selected = caseList[random];



      var txt = selected;



      window.location = ("https://instance.service-now.com/nav_to.do?uri=x_whba_table.do?sysparm_query=number=" + selected);



}


[/CODE]


View solution in original post

6 REPLIES 6

drjohnchun
Tera Guru

Hi Kaniel - I've written a blog on And the winner is... Randomly Selecting GlideRecords, which shows how to select a set of random records using a Scripted Filter.



Hope this helps.



Please feel free to connect, follow, mark helpful / answer, like, endorse.


John Chun, PhD PMP see John's LinkedIn profile

visit snowaid


ServiceNow Advocate

SaschaWildgrube
ServiceNow Employee
ServiceNow Employee

There is a Glide API to receive random data. Check this out:

https://github.com/saschawildgrube/servicenow-devtools/blob/master/update/sys_script_include_8bf245b...

The DevTools app contains a truckload of reusable scripts and
features to support your app development.

Fork at will!