Posts

Showing posts from June, 2021

Improving gs.addInfoMessage with gs.getMessage

old script: gs . addInfoMessage ( "The number " + current . number + " was already used by another " + recordClass + ". The " + recordClass + " number has been changed to " + newNum ); improved script: var sFeedback = gs . getMessage ( "The number {0} was already used by another {1}. The {1} number has been changed to {2}" , [ current . number , recordClass , newNum ]); gs . addInfoMessage ( sFeedback );

Improving the prevent duplicate number business rule

 as per the approach here: https://docs.servicenow.com/bundle/paris-platform-administration/page/administer/field-administration/concept/c_EnforcingUniqueNumbering.html?cshalt=yes here is a slightly improved version of the bus rule description : use this script to test: /*var grInc=new GlideRecord('incident'); grInc.newRecord(); grInc.short_description='test RDS'; grInc.number='INC5150xxx'; //--an existing number gs.print(grInc.insert());*/ script : ( function executeRule ( current , previous /*null when async*/ ) { //var curNum = current.number + ''; var curNum = current . getValue ( 'number' ); if ( curNum ) { var recordClass = current . getRecordClassName (); var now_GR = new GlideRecord ( recordClass ); now_GR . addQuery ( 'number' , curNum ); now_GR . query (); if ( now_GR . getRowCount () > 0 ) { var newNum = getNextObjNumberPadde

Script to prefix duplicate numbers

 belt and braces fix approach: https://docs.servicenow.com/bundle/paris-platform-administration/page/administer/field-administration/concept/c_EnforcingUniqueNumbering.html?cshalt=yes  but below is a fix script example to fix historic tickets with duplicate numbers //--sys_ids for duplicate numbers selected based on the latest created of the duplicates var bUpdate = false ; bUpdate = true ; //--dupl INCIDENTS duplIncidents ( bUpdate ); //--dupl CHANGE: duplChgRequests ( bUpdate ); //--dupl ST CHANGE: duplStChgRequests ( bUpdate ); printFullList (); var bDelete = false ; //bDelete=true; if ( bDelete ) { tidyUpSubProd ( bDelete ); } function duplIncidents ( bUpdate ) { var inc_sysids = 'd9f0e709db54a68074abffa9bf961xxx,8894b385db62e60074abffa9bf961xxx,cfbc2ccd4f51364057db0b318110cxxx' ; var sysidsARR = inc_sysids . split ( ',' ); for ( iC = 0 ; iC < sysidsARR . length ; iC ++) { renameDuplNumber ( s