how to add approvers record data with requested item table data csv import

jituksingh
Kilo Guru

Hi,

I am downloading all the records from requested item table (sc_req_item) in a CSV format but with data I also want to include all approver data record, like who were the approvers, when and who approved the request. I don't know how to achieve that. Can someone please help with my query, I see approval history but many items where we do have approvers data but approval history field is empty.

Please let me know if I need to provide some more data.

 

Regards,

Jitendra Singh

7 REPLIES 7

Also please note that I want to achieve this for old (already approved, closed tickets)

@jituksingh 

Fields on RITM

1) Approvers - List type reference to user

2) Approved On - Date/Time

3) Approved By -  Reference to User

something like this in after update BR on sysapproval_approver table

Condition: current.source_table == 'sc_req_item'

Script:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var ritm = new GlideRecord('sc_req_item');
    if (ritm.get(current.document_id)) {
        ritm.u_approved_by = current.approver;
        ritm.u_approved_on = new GlideDateTime();
        ritm.update();
    }

})(current, previous);

Another BR to update the Approvers List field on RITM on every insert of approval record

BR: After Insert

Condition: current.source_table == 'sc_req_item'

Script:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var ritm = new GlideRecord('sc_req_item');
    if (ritm.get(current.document_id)) {
        ritm.u_approvers = ritm.u_approvers + ',' + current.approver;
        ritm.update();
    }

})(current, previous);

You will also require a fix script to populate these custom fields on older RITM

I believe I have provided enough script and guidance and you can mark my response as correct.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@jituksingh 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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