- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
ok. understand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
