Complicated Date manipulation: display an escalate button on RITM

//--hide/show escalate button on RITM var bDisplay = false; var bDebug = false; //bDebug = true; //--check if the RITM has passed the estimated delivery time var sDelivery = grRITM.cat_item.delivery_time; var sDelivery_displ = sDelivery.getDisplayValue(); var sDelDT= new GlideDateTime(sDelivery ); if (!gs.nil(sDelivery) && (grRITM.active)) { //--PROBLEM: nowDateTime display format is: dd-mm-yyyy hh:mins:ss //--but RITM OpenedAt display format is: yyyy-mm-dd hh:mins:ss var s_todaysDate = gs.nowDateTime().toString(); var tdArr = s_todaysDate.split(' '); var tdArr2 = tdArr[0].split('-'); var d_TodaysDate = new GlideDateTime (tdArr2[2]+'-'+tdArr2[1]+'-'+tdArr2[0]+' ' + tdArr[1]); var iTodaysDate = d_TodaysDate.getNumericValue(); var d_TimeElapsed = new GlideDateTime(grRITM.opened_at); //d_TimeElapsed.addDaysLocalTime(parseInt(sDelivery_displ)); var iTimeElapsed = d_TimeElapsed.getNumericValue() + sDelDT.getNumericValue(); if (bDebug) { gs.addInfoMessage('delivery days: ' + sDelivery_displ); gs.addInfoMessage('open time + delivery time: ' + iTimeElapsed + '; date val TODAY:' + iTodaysDate + '; time passed?=' + (iTodaysDate > iTimeElapsed)); } if (iTodaysDate > iTimeElapsed) { //--check if the user belongs to groups var userSYSID = gs.getUserID(); var bTasks = false; var grTasks = new GlideRecord('sc_task'); grTasks.addActiveQuery(); grTasks.addQuery('request_item', grRITM.sys_id); grTasks.query(); if (grTasks.getRowCount() > 0) { bTasks = true; } var bRoles = gs.hasRole("admin"); var bGroups = (gs.getUser().isMemberOf('_Service Request_Fulfilment') || gs.getUser().isMemberOf('CustomerServices_SD_Escalations')); if (bDebug) { gs.addInfoMessage('test active tasks: ' + bTasks); gs.addInfoMessage('test grp memberships: ' + bGroups); gs.addInfoMessage('test admin role: ' + bRoles); } bDisplay = (bTasks && (bRoles || bGroups)); } } return bDisplay;

Comments

Popular posts from this blog

GlideRecord setValue

variable advanced reference qualifier example

URL link in addInfoMessage