Skip to main content

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

ServiceNow check for null or nil or empty (or not)

Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g.  var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord  addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ())  option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){

Service Catalog: variable advanced reference qualifiers

Call a script include to apply a reference qualifier on a catalog item variable: - variable reference qualifier dependent on another variable selection, in this case a variable referencing sys_user (requested_for) On the catalog item form. variable name to apply ref qual filter : retail_equipment variable reference qualifier (on cmdb table ): javascript : new  refqual_functions (). lostStolen_getAssignedCIs (); client-callable script include ( refqual_functions)  function : lostStolen_getAssignedCIs : function (){         //--called from variable set client script, for lost/stolen request (service catalog)     gs . log ( current . variables . requested_for , 'retail_lostStolen_getAssignedCIs' );         return ( 'install_statusNOT IN8,7^owned_by=' + current . variables . requested_for );             //owned_by=1269b79937f1060041c5616043990e41^install_statusNOT IN8,7            },