SHARE
TWEET

Untitled

a guest Apr 18th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Does the work on each loop.
  3.  * @param {Number} [limit=10] - The number of records to process per loop.
  4.  * @param {Number} [currentNumber=0] - The number of records that have been processed so far, by all previous loops.
  5.  */
  6. function eventWrapper(limit, currentNumber) {
  7.    
  8.     var EVENT_NAME = 'EVENT.NAME.HERE'; //todo: Update this to the name of the event you've created.
  9.     var TABLE_NAME = 'TABLE_NAME_HERE'; //todo: Update this to the name of the table containing the records you're processing
  10.     var QUERY = 'some_query=here'; //todo: Put your query here
  11.    
  12.     var gr = new GlideRecord(TABLE_NAME);
  13.    
  14.     //Set default values
  15.     limit = Number(limit) > 0 ? Number(limit) : 10; //Default: 10
  16.     currentNumber = currentNumber > 0 ? currentNumber : 0; //Default: 0
  17.    
  18.     gr.setLimit(limit);
  19.     gr.addQuery(QUERY);
  20.     gr.query();
  21.     if (!gr.hasNext()) {
  22.         gs.log('EDR: [Script name here] completed with ' + currentNumber +
  23.             ' total records processed.');
  24.         return; //No more records to process. Halt function, and loop.
  25.     }
  26.     while (gr.next()) {
  27.         /*
  28.          * Do something to a batch of records here, based on the limit parameter
  29.          */
  30.         currentNumber++;
  31.     }
  32.     //Log a progress update
  33.     gs.log('EDR: event wrapper processed ' + currentNumber +
  34.         ' records so far. Triggering the next loop.');
  35.     //Trigger the event again
  36.     gs.eventQueue(EVENT_NAME, gr, limit, currentNumber);
  37. }
  38.  
  39. eventWrapper(event.parm1, event.parm2);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top