Expire RITM Approvals

leahp
Kilo Guru

I have 30 catalog items that require approval from different users (based on catalog item).   We have found that there are a lot of RITMs from several years ago that are still pending approval so we want to expire approvals after a certain time.


Specifically, we want to:

  • Send a reminder email to the approver if the Approval Record is Requested and its been 5 or more days since the approval record was created.   Notification should contain link to approval record
  • Cancel RITM if it was created more than 30 days ago and approval is still requested
  • These will only apply to Requested Items

Need some very specific, guidance

3 REPLIES 3

She Sull
Giga Guru

Run a daily job to find approval records created within the desired time frame that have not been approved. In that daily job for records that meet that condition trigger an event. Create a reminder notification that is triggered by the event.



Run another daily job to find approvals that are 30 days or older, in that script set the approval state to the desired (closed) state.


manishm
Mega Guru

Hi Leah,



Here's a high level approach (sorry its a combination of pseudocode and script). Maybe you can post the actual script once done.



Step 1 - Create a notification that works corresponding to an event and sends the user a reminder email with the URI.



Step 2 - Create a scheduled job that runs daily to loop through sysapproval_approver table and search for :


1) State = requested


create_date> 5 and < 30 days


Approval_for.number LIKE "REQ%"


Loop through these and generate the above event so a reminder email is sent out.



2) State = "Requested"


Create Date > 30 days


Approval_for.number (sysapproval field) LIKE "REQ%"


Query


grReq = new GlideRecord('sc_request')


Loop through the records.


for each record


  rReq.initialize();


grReq.get(sysapproval);


if(grReq.next()) {


  grReq.state = "Cancelled";


  grReq.update();


}


END



Hope this helps.



Manish


harishdasari
Tera Guru

Hi,



My suggestion is



1).   Send a reminder email to the approver if the Approval Record is Requested and its been 5 or more days since the approval record was created.   Notification should contain link to approval record...


A).   create a email notification on REQUESTED ITEM table and specify conditions like when to send is created is more than 5 days and specify the condition as current.variables.yourmanagerfield


so this will trigger email to approver as reminder.



2). Cancel RITM if it was created more than 30 days ago and approval is still requested



A). Var ritm = new GlideRecord('sc_req_item');


ritm.addQuery('active', true);


ritm.addQuery('state', 'pending');


ritm.addQuery('sys_created_on', '>=' , gs.daysago(5));


ritm.query();


while(ritm.next())


{


rim.state = '7';   // cancelled


ritm.update();


}



i am not infront of my laptop, But tried to help with coding. Please change the coding as per your requirement.



Thank you