Skip to main content

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) && ( { //--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;


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