RITM Issued and Approved date.

Nageshwari P
Tera Contributor

Hi team,

I have a requirement to extract the timings of RITM created and RITM approved excluding after business hours, National holidays and weekends. Please help me to achieve how to extract the data.

 

Thanks & Regards,

Nageshwari P

4 REPLIES 4

Zack Hilacan1
Mega Sage

Hello @Nageshwari P ,

 

Hello this is achievable by creating a schedule in the cmn_schedule table specific to the dates you mentioned.

Can also navigate through (System Scheduler > Schedules > Schedules).

Schedules 

You can then create a script whether it is business rules/scheduled job etc., to load that schedule and create a logic depending on your needs to extract those RITM.

 

I'm quite confused on your inquiry though, when you mean "extract the timings" do you meant the dates and time of those record?

Ankur Bawiskar
Tera Patron
Tera Patron

@Nageshwari P 

you will get to know the RITM created time, you can get the approval time from sysapproval_approver record

Then find the difference using your schedule (the schedule should exclude holidays, weekends etc

Recently I shared solution for something similar, check that

calculate Duration and Business Duration in scoped application 

also check these links

subtract time from schedule to update task due date 

Calculate Date By Adding or Subtracting Time With A Schedule 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Nageshwari P 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Nageshwari P
Tera Contributor

Hi,
I have written the below script in scheduled jobs to export the the list of ritm created and approved data. Can you help me to write the script for the above mentioned conditions.
Script:

var grApprover = new GlideRecord('sysapproval_approver');

grApprover.addQuery('state', 'approved');

grApprover.query();

// if (!grApprover.hasNext()) {

//     gs.log("No approved approval records found.");

//     return;

// }

 

// CSV Header

var csvContent = "Approval Number,Approver,Approval State,Approval Date,Sysapproval\n";

 

while (grApprover.next()) {

    csvContent += grApprover.getValue('sys_id') + "," +

        grApprover.getDisplayValue('approver') + "," +

        grApprover.getValue('state') + "," +

        grApprover.getValue('sys_created_on') + "," +

        grApprover.getDisplayValue('sysapproval') + "\n";

}

 

// Save as an attachment

var fileName = "Approved_Approvals_" + gs.nowDateTime() + ".csv";

var tableName = new GlideRecord("sys_attachment");

tableName.initialize();// Attach to sys_attachment

var recordSysId = gs.generateGUID(); // Generates a unique record ID

 

var attachment = new GlideSysAttachment();

attachment.write(tableName,fileName, "text/csv", csvContent);

 

gs.log("Exported Approved Approvals and saved as an attachment: " + fileName);

 

Thanks & regards,
Nageshwari P.