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; }, */


Popular posts from this blog

URL link in addInfoMessage

var ga=new GlideAjax('gld_HR_ajax'); ga.addParam('sysparm_name', 'checkEmployeeNumber_hrProfile'); ga.addParam('sysparm_hrprofilenumber', g_form.getValue('number')); ga.addParam('sysparm_employeenumber', newValue); ga.getXMLAnswer(function(answer) { if (answer!='undefined' && answer!=''){ var navURL="<a style='text-decoration:underline;color:blue'" + answer + ">" + answer + "</a><img width='3' src='images/s.gif'/>"; var sMsg='The employee number entered already exists on another HR Profile ' + navURL; //alert(sMsg); g_form.showErrorBox('employee_number', 'error - please check'); g_form.addInfoMessage(sMsg); } });

GlideRecord setValue

setValue(String name, Object value) Sets the specified field to the specified value. Normally a script would do a direct assignment, for example,  gr.category = value . However, if in a script the element name is a variable, then  gr.setValue(elementName, value)  can be used. When setting a value, ensure the data type of the field matches the data type of the value you enter. This method cannot be used on journal fields. If the value parameter is null, the record is not updated, and an error is not thrown!/api_doc?v=madrid&id=r_GlideRecord-setValue_String_Object