//--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;
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 )){
Comments
Post a Comment