Skip to main content

Posts

Showing posts from March, 2021

get a field value in the glideAggregate

Must include a groupby clause in order for the getValue (or getDisplayValue() on a reference field) to work var REQsysid = '3eac6cbddb75a81081fb49a23996xxxx' ; var agg = new GlideAggregate ( 'sc_req_item' ); agg . addQuery ( 'request' , REQsysid ); agg . addAggregate ( "COUNT" ); agg . groupBy ( 'short_description' ); agg . query (); var answer = 0 ; while ( agg . next ()) { gs . print ( agg . getAggregate ( "COUNT" )); gs . print ( 'SD:' + agg . short_description . getValue () ); }

GetRowCount() versus GlideAggregate

 GetRowCount is not best practice, instead use GlideAggregate see  getrowcount example: var agg = new GlideAggregate ( 'sc_req_item' ); agg . addQuery ( 'request' , '3eac6cbddb75a81081fb49a2399xxxxx' ); agg . addAggregate ( "COUNT" ); agg . query (); if ( agg . next ()) { var answer = agg . getAggregate ( "COUNT" ); gs . print ( answer ); }

Write to script processing table (extended from DL) to execute stored gliderecord scripts

write gliderecord script to a table which can then be executed on a schedule using  GlideScopedEvaluator () -business rules to trigger the update action -script include to store entries in a scheduled script table (extended from DL  [dl_matcher]  so as to be outside of license cost) -scheduled job to iterate through the scheduled script table and execute rows ready to be processed CODE : new table extended from DL table (as per  Create custom data lookups (servicenow.com) Business rules - just examples REQ/RITM : after insert BR on REQ table, better solution would be a timer on the RITM workflow with the code in there, but this is an alternate solution if the workflow couldn't be updated for whatever reason. The challenge was picking up how many RITMs present on the REQ within the insert action end to end, which proved difficult using business rules alone ( function executeRule ( current , previous /*null when async*/ ) { //--REQ short description aut...