logo

NJP

Approval Summarizer for Group Approvals

Import · Sep 21, 2019 · article

Recently I have see many questions regarding showing approval summary on Group approval which is not available out of the box; so I thought of creating a blog for same.

https://community.servicenow.com/community?id=community\_question&sys\_id=a6f6f66cdb0c809023f4a345ca9619f8

https://community.servicenow.com/community?id=community\_question&sys\_id=119c822fdb333b005ed4a851ca96196d

https://community.servicenow.com/community?id=community\_question&sys\_id=c2a4f224db48809023f4a345ca961918

This blog gives you an overview on how to display approval summary for Groups Approvals which is not present out of the box. It would display the variable name and their values corresponding to the RITM for which group approval is present.

For User Approvals there is an Approval Summarizer which displays the information about the RITM along with all the details.

But such approval summary is not available for Group Approvals. So here is the custom code to show the approval information.

You can add your customization as per your own need here and enhance the code the way you want i.e. the html table style, extra information etc

Note: Currently it would show information for only those variables which are having value and not for empty variables.

Also it will display information only when table is RITM; for all other Group approval it will display static message

Steps:

  1. Create an UI Macro
  2. Create a formatter and link the macro created in step 1
  3. Add this formatter on Group Approval form layout

1) UI Macro:

Name: custom_display_variable_summary

XML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<!-- 
    <style>
table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
}

td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: #dddddd;
}
</style>
     -->

    <style>
  table {
    border-collapse: collapse;
  }
  th, td {
    border: 1px solid #ccc;
    padding: 10px;
    text-align: left;
  }
  tr:nth-child(even) {
    background-color: #eee;
  }
  tr:nth-child(odd) {
    background-color: #fff;
  }            
</style>


    <b>Variable Summary</b>
    <br/>

    <g2:evaluate var="jvar_rec" jelly="true" object="true">
        var tableName = current.parent.sys_class_name;
        tableName;
    </g2:evaluate>

        <j2:choose> 
            <j2:when test="$[tableName == 'sc_req_item']">
    <g2:evaluate var="jvar_jsonObj" jelly="true" object="true">
        var ritmSysId = current.getValue('parent');
        var set = new GlideappVariablePoolQuestionSet();
        set.setRequestID(ritmSysId);
        set.load();
        var vs = set.getFlatQuestions();
        vs;
    </g2:evaluate>

    <table cellspacing="0" cellpadding="0" width="100%">
        <th>NAME</th>
        <th>VALUE</th>
     <j2:forEach var="jvar_json" items="$[vs]"> 
        <j2:if test = "$[jvar_json.getLabel()!= '' &amp;&amp; jvar_json.getDisplayValue()!= '']"> 
            <tr><td class="block"> $[jvar_json.getLabel()] </td><td class="block">$[jvar_json.getDisplayValue()] </td></tr>
        </j2:if> 
    </j2:forEach>
        </table>
            </j2:when>
            <j2:otherwise>
            <p>No variable summary to display</p>
            </j2:otherwise>
            </j2:choose>

</j:jelly>

2) Formatter: In left navigation type formatters; give below details

Name: Approval Group Summary

Formatter: custom_display_variable_summary.xml

Table: Group approval (sysapproval_group)

Type: Formatter

Screenshot below

image

3) Add the formatter to the form layout of Group approval; see the Formatter added at the end in the Selected list in right hand side

image

Example: As you can see the RITM has all the variable information:

image

Variable Summary on Group Approval:

image

Hope this helps the community team members.

Regards

View original source

https://www.servicenow.com/community/developer-blog/approval-summarizer-for-group-approvals/ba-p/2286091