Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
dvp
Mega Sage
Mega Sage

Here is the second article in the series of Portal diaries. In this article, I would like to discuss about displaying the summary of approval record in Service Portal. As customers started using ServiceNow widely the idea of approval process drifted into other modules like Resource plans, Issues, stories, hr case, test plans which are just a few to mention.

In my opinion the OOB approval page in Service Portal is only focusing on RITM approval displaying all the variables whereas for other tables it is only showing the following four fields (Short description, Opened by, Start and End dates if applicable).

Backend form view of ServiceNow approval record displays the approving field summary with the help of approval summarizer UI macro. If the specific table has approval view the UI macro (Approval Summarizer) displays fields of this view, if not the default view of form is shown.

Here is the screenshot of a change request fields in an approval record using approval summarizer.

find_real_file.png

This similar solution can be implemented on Service Portal via a custom script include taking GlideReocrd as an input and outputting the fields of a default view along with its field positions. When I was working on a different requirement I came across one of the methods in $sp portal API called getForm and a <sp-model> tag to the render form.

Here is the format for calling getForm api and using it in HTML view

HTML Template

<sp-model form-model="data.f" mandatory="mandatory"></sp-model>

Server Code

data.f = $sp.getForm( table_name, sys_id_of_record);

This solution seemed clean until I realized that the getForm method display fields with edit access   which is undesired. But on a positive note getForm method returns the fields after all the rules like UI policies, client scripts, ACL's and even dictionary level read only. This generates me an idea of forcing all the fields to be read only .

In order to make all the fields read only, I hacked the data.f object and updated the sys_readonly property.

Here is the server script to make all the fields of a record read only

data.f = $sp.getForm( table_name, sys_id);

for (var field_name in data.f._fields) {

        data.f._fields[field_name]["sys_readonly"] = true;

}


Screenshot of Story form in approval widget

find_real_file.png

Screenshot of HR case form in approval widget

find_real_file.png

Here is more info about what all the getForm returns

gs.log('display value: ' + data.f.display_value)

gs.log('ui acations: ' + data.f._ui_actions)

gs.log('short description: ' + data.f.short_description)

gs.log('plural : ' + data.f.plural)

gs.log('view_titile: ' + data.f.view_title)

gs.log('_pref: ' + data.f._perf)

gs.log('_sections: ' + data.f._sections)

gs.log('label: ' + data.f.label)

gs.log('title: ' + data.f.title)

gs.log('_fields: ' + data.f._fields)

gs.log('_formatters: ' + data.f._formatters)

gs.log('sys_id: ' + data.f.sys_id)

gs.log('view: ' + data.f.view)

gs.log('scratchpad: ' + data.f.g_scratchpad)

gs.log('_view: ' + data.f._view)

gs.log('attachmentGUID: ' + data.f._attachmentGUID)

gs.log('client_script: ' + data.f.client_script)

gs.log('related_list: ' + data.f._related_lists)

gs.log('table: ' + data.f.table)

gs.log('policy: ' + data.f.policy)

As in this article I talked more about properties of fields. Here are the all the properties of a field

gs.log('sys_mandatory : ' + data.f._fields.cmdb_ci.sys_mandatory)

gs.log('visible : ' + data.f._fields.cmdb_ci.visible)

gs.log('dependentField : ' + data.f._fields.cmdb_ci.dependentField)

gs.log('dbType : ' + data.f._fields.cmdb_ci.dbType)

gs.log('label : ' + data.f._fields.cmdb_ci.label)

gs.log('sys_readonly : ' + data.f._fields.cmdb_ci.sys_readonly)

gs.log('type : ' + data.f._fields.cmdb_ci.type)

gs.log('mandatory : ' + data.f._fields.cmdb_ci.mandatory)

gs.log('refTable : ' + data.f._fields.cmdb_ci.refTable)

gs.log('displayValue : ' + data.f._fields.cmdb_ci.displayValue)

gs.log('readonly : ' + data.f._fields.cmdb_ci.readonly)

gs.log('hint : ' + data.f._fields.cmdb_ci.hint)

gs.log('name : ' + data.f._fields.cmdb_ci.name)

gs.log('attributes : ' + data.f._fields.cmdb_ci.attributes)

gs.log('reference_key : ' + data.f._fields.cmdb_ci.reference_key)

gs.log('readonlyClickthrough : ' + data.f._fields.cmdb_ci.readonlyClickthrough)

gs.log('choice : ' + data.f._fields.cmdb_ci.choice)

gs.log('value : ' + data.f._fields.cmdb_ci.value)

gs.log('max_length : ' + data.f._fields.cmdb_ci.max_length)

gs.log('ed : ' + data.f._fields.cmdb_ci.ed)

Please find the attached XML of updated Approval Record widget.

Edit: updated the widget to include record attachments

Previous blogs in this series

Portal diaries: Service Portal — Making Rejection Comments Mandatory on Approval Record

Portal diaries: Service Portal — Multiple Catalogs (Part 1)

51 Comments