Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

David Pichard
Mega Guru

//See if any closure records exist
//--------------------------------------------------------------
var ct = new GlideRecord('u_ks_task_closure');
ct.query();
while(ct.next()){

// If closure record end date is past today then add task record
//---------------------------------------------------------------
if(new Date().getTime() > new Date(ct.u_closure_date.substring(0,4), (ct.u_closure_date.substring(5,7)-1), ct.u_closure_date.substring(8,10)).getTime()){

  //Find RITM record, change it's status to in progress and add a task
  //---------------------------------------------------------------
  var ritm = new GlideRecord('sc_req_item');
    if(ritm.get('number',ct.u_ritm_number)){
   
        //If ritm wasn't rejected update it's status
        //-----------------------------------------
        if(ritm.approval != 'rejected'){
          ritm.active = true;
          ritm.state = 2;
          ritm.stage = "executing"
          ritm.comments = "New task added to remove access since end date ("+ct.u_closure_date+") has passed.";
          ritm.update();
        }else{
          continue;
        }  
    }

  //Get assignment group for this particular task/RITM
  //---------------------------------------------------------------
  var assignGroup = "";
  var group = new GlideRecord('u_ks_task_closure_helper_table');
  if(group.get('u_catalog_item',ritm.cat_item.sys_id)){
      assignGroup = group.u_task_closure_group.sys_id;
  }

  // Create new Task record and tie it to the parent ritm record
  //---------------------------------------------------------------
  var newTask = new GlideRecord('sc_task');
  newTask.initialize();
  newTask.short_description = "REMOVE ACCESS: '"+ritm.cat_item.name+"' for "+ritm.request.requested_for.name;
  newTask.description = "Access to this resource has expired and needs to be removed";
  newTask.assignment_group = assignGroup;//fulfillment group from helper table
  newTask.request_item = ritm.sys_id;//sys id of parent ritm
  newTask.parent = ritm.sys_id;//sys id of parent ritm
  newTask.insert();

  // Delete record from closure table
  //---------------------------------------------------------------
  ct.deleteRecord();  


}//End if closure end date is past today

}//end loop

2 Comments