Skip to main content

Dynatrace APM (problem to incident): converting a DT date to SN format




 



_formatDateforInc: function(UTC_date) { //--UTC format from Dynatrace: 02:39 (UTC) 28.07.2021 //--make it ServiceNow friendly var sReturn = ""; try { var sUTC = UTC_date; var sUTC_Arr = UTC_date.split("(UTC)"); var sDtTr=sUTC_Arr[1].trim(); var sDateOrderedArr=sDtTr.split("."); var sDateOrdered=sDateOrderedArr[2]+"-"+sDateOrderedArr[1]+"-"+sDateOrderedArr[0]; //--2021-07-28 gs.print(sDateOrderedArr[2]); var sDateFormatted = sDateOrdered + " " + sUTC_Arr[0].trim() + ":00"; var sGDTDate= new GlideDateTime(sDateFormatted);//--this appears to take care of UTC-GMT/BST out of the box /* var sBST = this._checkBST(sUTC_Arr[1].trim()); if (sBST=='BST'){ //--add an hour for British Summer Time sGDTDate.addSeconds(3600); //add 1 hour )1 hour=3600 secs) }*/ sReturn = sGDTDate; } catch (ex) { sReturn = ""; } return sReturn; },
/*_checkBST: function(UTC_date) { /*//--UTC format from Dynatrace: 02: 39(UTC) 28.07 .2021 var d= new Date(2021, 6, 28, 2, 39, 0);//NOTE month is zero-indexed! so 6=July gs.print(d.toLocaleString('en-GB', { timeZone: 'Europe/London' })); During British Summer Time (BST), civil time in the United Kingdom is advanced one hour forward of Greenwich Mean Time (GMT), in effect changing the time zone from UTC+00:00 to UTC+01:00, so that mornings have one hour less daylight, and evenings one hour more.[1][2] var d2=new Date(2021, 6, 28, 2, 39, 0); gs.pri
 _formatDateforInc: fun nt(d2.getTimezoneOffset());//--420 (7h) for PDT> indicsates british summer time. 360 (6h) would be GMT+0.00
*/ var sReturn = 'BST'; try { var date_arr = UTC_date.split('-'); //--var d2=new Date(2021, 6, 28, 2, 39, 0); //--example var d2 = new Date(date_arr[2], date_arr[1], date_arr[0]); if(d2.getTimezoneOffset() < 420){ //--420 (7h) for PDT> indicates british summer time, GMT+1.00. 360 (6h) would be GMT+0.00 sReturn='GMT'; } } catch (ex) { sReturn=''; } return sReturn; }, */

Comments

Popular posts from this blog

ServiceNow check for null or nil or empty (or not)

Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g.  var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord  addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ())  option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){...

Code a pause/wait - gs.sleep or gs.wait alternative, pause script for specified seconds (timer)

Code a pause/wait - gs.sleep / gs.wait alternative, pause script for specified seconds (timer)  e.g. 10 seconds: do_sleep ( 10000 ); function do_sleep ( milliseconds ) { var start = new Date (). getTime (); for ( var i = 0 ; i < 1e7 ; i ++) { if (( new Date (). getTime () - start ) > milliseconds ){ gs . print ( 'waking up!' ); break ; } } }