ServiceNow - Approval view of demand form: using a formatter

 

Approval Summarizer formatter

(Displaying and amending view of item to be approved within the approval record)

 

Introduction:

When opening and viewing an approval record/form, you will typically not see the actual task or record that you are about to approve or reject. Instead, you would always see a reference field pointing to the item that needs to be approved, whether it is a change request, request item, demand, Aetc.

There is however, a feature provided Out-Of-The-Box by ServiceNow, which allows a summary to be displayed of the item to be approved within the same approval record. This, however, requires a small customisation to utilise.

Since (at least) the Paris release, this feature had become available on the approval form without requiring any customisations.

 

Displaying item to be approved (on the backend approval form):

If the 'Approval Summarizer' section is not already available on the approval form, then you can add it by performing the following instructions.

To display the 'Approval Summarizer' formatter, which shows a summary of the item to be approved within the same approval record, right-click on the form header and select: Confirgure > Form Layout. Once in the configuration page, move the 'Approval Summarizer' formatter from the Available pane over to the Selected pane. Note: its position amongst the field does not matter, you can even place it in the top. After that click the Save button.

 

In order to display the 'Approval Summarizer' formatter on a service portal page within the approval page, you will need to perform the following:

  1. Create a new widget and add it within the 'approval' page, under the approval record widget.
  2. Add the following code within the 'HTML Template' field:

<sp-attachment-manager table="data.table" sys-id="data.form._attachmentGUID" omit-edit="true"></sp-attachment-manager>
<fieldset disabled>
    <sp-model form-model="data.form" mandatory="mandatory"></sp-model>
</fieldset>

3. After that, add the following script within the 'Server Script' field:

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
    
    data.uri = new GlideSPUtil().getPageUri();
    var val = getParameter(data.uri);
    data.parm_table = getParameter('table');
    data.parm_sys_id = getParameter('sys_id');
    
    var approval_record = new GlideRecord(data.parm_table);
    approval_record.get(data.parm_sys_id);
    
    var task = new GlideRecord(approval_record.sysapproval.sys_class_name);
    task.get(approval_record.sysapproval.sys_id);
    
    if (task.sys_class_name != 'sc_req_item') {
        data.table = task.getTableName();
        data.form = $sp.getForm( task.getTableName(), task.sys_id, "active^true", "approval");
        for (var prop in data.form._fields) {
            data.form._fields[prop]["sys_readonly"] = true;
        }
    }
    
    function getParameter(parm_name) {
        var uri = new GlideSPUtil().getPageUri();
        var uri_parms = uri.split('&');
        for (var i=0; i<uri_parms.length; i++) {
            if (uri_parms.indexOf('=') != 0) {
                var parm_name_val = uri_parms[i].split('=');
                if (parm_name_val[0] == parm_name)
                    return parm_name_val[1];
            }
        }
    }
    
})();

 

Now, reload the approval page and you should notice that a summary of the item to be approved/rejected is now visible under the main approval widget.

 

Amending the view of item to be approved:

To be able to amend the view of the 'Approval Summarizer' form view, then perform the following steps:

  1. Navigate to the target table of approval, e.g. the change request form, or the request item form.
  2. Ensure that there is a form view named as: 'approval', if so, then skip the next step (step #3).
  3. If there is no existing view for the form with the name: 'approval', then create a new one and ensure to name it as: 'approval'.
  4. Finally, edit the form view called 'approval' however you like, as the way you amend it is going to show within the 'Approval Summarizer' formatter on the backend approval form and on the approval portal page.

 

 

Comments

  1. Great article again - but FYI you doubled up on the section title "Displaying item to be approved (on the backend approval form):" should be '(in Service Portal)'

    ReplyDelete

Post a Comment

Popular posts from this blog

GlideRecord setValue

URL link in addInfoMessage