Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to generate a report to analysis the RITM stage, approver and approval duration

major li
Tera Guru

Hi community, 

I have request to generate a report to analysis the duration of each stage in RITM level, together with the approvers in each stages. I could find the metric_instance to calculate the duration of each stage, however, i could not find a table to calculate the approvers under specific stage, the sysapproval_approver table will only log the current stage.

Could you please help me? thank you. 

1 ACCEPTED SOLUTION

major li
Tera Guru

Hi community,

here is the workaround.

in the [sysapproval_approver] table there is a wf_activity reference field liked to the workflow and stages. this field is not active by default but it is populated with the right value, even though I cannot understand why it is configured that way.

in the [metric_instance] table, there is definition field equals "Stage Duration Calculation" & value field equals wf_stage (type string).

So I created a database view to join [metric_instance], with [wf_activity] and [wf_stage] table to present the duration of each stage and exported [sysapproval_approver] table to the requester. She can use 3rd party analysis tool to analyze these 2 tables with the workflow stage as the key.

root cause why I don't join [sysapproval_approver] and [metric_instance]: sometimes there are multiple approvers involved in one stage, if I do so, it will be misleading because the audience will misunderstood that during one stage all approvers need to approve but in reality, only one of them will be enough. as a result the stage duration calcuation from the table will be wrong. 

View solution in original post

6 REPLIES 6

MaxMixali
Kilo Sage

You're correct that this is a common challenge in ServiceNow. The sysapproval_approver table doesn't inherently track which approval stage each approver belongs to. Here are some approaches to solve this you can try do do this: 

Use this code Javascript to usese the wf_history table (Workflow History)

 

 

// Query example var gr = new GlideRecord('wf_history'); gr.addQuery('id', ritm_sys_id); // Your RITM sys_idgr.addQuery('activity_definition_name', 'CONTAINS', 'Approval'); // Filter for approval activities gr.query();while(gr.next()) { // gr.name = Stage/Activity name // gr.actual_duration = Duration of that activity // gr.result = Approval result (approved/rejected) }

 

 

 

Additonal notes:

 

The wf_history table captures:

  • Each workflow activity (including approval stages)
  • Duration of each activity
  • Who acted on it
  • The result

2. Cross-reference sysapproval_approver with wf_history

You can correlate the two tables:

  • Use wf_history to identify the stage names and durations
  • Match sysapproval_approver records to stages based on timestamps
  • Link approvers to stages by comparing sys_created_on dates

3. Custom solution: Create a tracking table

If you need ongoing tracking, consider:

  • Creating a custom table to capture stage + approver relationships
  • Using a Business Rule on sysapproval_approver to log the current stage context when an approval record is created
  • Store the stage information (perhaps from sc_req_item.stage or workflow context)

4. Check for Stage field customization

Some implementations add a custom field to sysapproval_approver:

  • Check if there's a field like u_approval_stage or u_stage
  • This would be a custom enhancement
  •  

 

Hi @MaxMixali,

 

To help the Community, I'm flagging your reply as #AI_slop.

ok. understand

Ankur Bawiskar
Tera Patron
Tera Patron

@major li 

this is a challenging requirement as approval history per stage by default at the RITM is not tracked

💡 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