Posts

Showing posts from March, 2018

Using hard coded constants in script includes

EXAMPLE: var ChangeCheckConflicts = Class . create (); ChangeCheckConflicts . prototype = {     //System properties     CHANGE_CONFLICT_MODE : 'change.conflict.mode' ,     CHANGE_CONFLICT_CURRENTCI : 'change.conflict.currentci' ,     CHANGE_CONFLICT_CURRENTWINDOW : 'change.conflict.currentwindow' ,     CHANGE_CONFLICT_BLACKOUT : 'change.conflict.blackout' ,     CHANGE_CONFLICT_RELATEDCHILDWINDOW : 'change.conflict.relatedchildwindow' ,     CHANGE_CONFLICT_RELATEDPARENTWINDOW : 'change.conflict.relatedparentwindow' ,     initialize : function ( current ) {                 this . mode = gs . getProperty ( this . CHANGE_CONFLICT_MODE );

insert line break in gs.addInfoMessage

//--<br/> rather than \r\n (\r\n\ works in work_notes) var sMsg = 'line 1<br/>' ; sMsg = sMsg + 'line 2<br/>' ; sMsg = sMsg + 'line 3' ; gs . addInfoMessage ( sMsg ); //--seems to do the trick!

Code a processor with parameter

Image
Example processor--code a processor which: - pushes back if the user is not an admin - if the user is an admin, takes a parameter passed in and uses it to set a system property - processor url: https://<yourinstance>.service-now.com/scheduled_sites_set_endday.do?endDayVal=7  ( function process ( g_request , g_response , g_processor ) {         if ( gs . hasRole ( "admin" )){         //--set the end day system property for the 'sites list of incidents' scheduled job to pick up         var endDay = g_request . getParameter ( 'endDayVal' );         g_processor . writeOutput ( 'text/plain' , 'endDay parameter: ' + endDay + '\r\n' );         if (! gs . nil ( endDay )){             var grSP = new GlideRecord ( 'sys_properties' );             if ( grSP . get ( 'sys_id' , 'ef1871be374113808ca1138943990e18' )){                 grSP . value = endDay ;                

How to add an 'date>=today and date less than 20 days' type date query to a glideRecord

//--store the day_end in a configurable sys property, e.g. '20' var day_end = gs . getProperty ( 'sch.sitemigration.enddate' ); //--set to integer 20 gs . print ( day_end ); var day_end_minus = - Math . abs ( day_end ); gs . print ( day_end_minus ); //--gr is your gliderecord you are adding queries to: var qc = gr . addQuery ( 'u_scheduled_date' , '<=' , gs . daysAgo ( day_end_minus )); qc . addCondition ( 'u_scheduled_date' , '>=' , gs . daysAgoEnd ( 0 )); gr . orderBy ( 'u_scheduled_date' ); gr . query ();

How to add new custom fields to the 'copy change' functionality (sys property)

Copy change button calls a read-only script include entitled 'ChangeUtilsSNC' com.snc.change_request.copy.attributes sys property defines the , separated list of fields to include in the copy operation

Carriage returns causing problems in REST request?

Image
following seems to do the trick: var wn_formatted =   work_notes . replace ( /\r?\n|\r/g , ';' ); //replaces carriage return with ; since discovered that using  JSON . stringify ()  on the string, and  setStringParameter in lieu of  setStringParameterNoEscape  in the REST message is safer belt and braces!

GlideAggregate function with passed-in parameters

var queryParam = 'email' ; checkDuplUsers ( true , queryParam ); function checkDuplUsers ( activeUser , queryParam ){   var ga = new GlideAggregate ( 'sys_user' );   ga . addAggregate ( 'COUNT' , queryParam );   if ( activeUser ){     ga . addActiveQuery ();   }   ga . addHaving ( 'COUNT' , '>' , 1 );   ga . query ();   gs . log ( "The following " + ga . getRowCount () + " users are duplicate on " + queryParam );   while ( ga . next ()) {       gs . log ( "GatherDuplicates " + queryParam + " " + ga . getAggregate ( 'COUNT' , queryParam ) + " => " + ga . getElement ( queryParam ));          } }

Pull in a list of sys ids into a report (reference a script include)

Image
Report : sys id filter : javascript : new refqual_functions (). report_sysidlist ( 'auth_request' ); script include cod e, note: the client callable box must be ticked (note, the script include contains some bonus code for refreshing group membership of a group to contain open approvals used for chasing up approvals via a scheduled email of the report) var refqual_functions = Class . create (); refqual_functions . prototype = {     initialize : function () {         //gs.log('test initialise--', 'refqual_functions');                     },         report_sysidlist : function ( filterToApply ){         //--build up list of sysids to return to a report condition field filter by sysid         gs . log ( 'test--' , 'refqual_functions' );                 var ids = [];         if ( filterToApply == 'auth_request' ){             //--build up a list of sysids to return to ' Auth Process