- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 08-01-2018 04:04 PM
You'd think that displaying a Requested Item Variables in a read-only format would be easy, right? We'll unfortunately it's not, especially in Service Portal (if it is then the solution is well hidden!). I must have read a dozen different posts asking how to do this and seen almost as many different solutions. Having evaluated them all I combined a few different ones to come up with what to me looks like the easiest path.
Overview
The 'Form' widget in Service Portal handles the rendering of form views that are configured within the platform. If you include the 'Variable Editor' in the form layout then it will appear on the Service Portal page as part of this widget. The variables are displayed using a second embedded widget sp-variable-editor. However, the variables are editable and there's no OTB way to make them read-only. The solution I used was to clone sp-variable-editor and add a few lines of code to make the fields read-only. Finally, I updated the Service Portal UI Formatter to reference the new widget so that it's used by the Form instead of the OTB one.
Instructions
- Clone the 'sp-variable-editor' widget (I called mine sp-variable-viewer')
- Edit the new widget and add the following code at line 16 (after g_form = gFormInstance;)
var allFields = g_form.getFieldNames();
for(var fieldName in allFields){
g_form.setReadOnly(allFields[fieldName], true);
}
- Modify the com_glideapp_servicecatalog_veditor sp_ui_formatter record to point to the cloned widget (nav_to.do?uri=sp_ui_formatter.do?sys_id=d71194730b012200b0b02c6317673a29).
And that's it, your variables should now be read-only!
Sources
Thanks to @satish for his post which provided the method to edit the widget
The editing of the formatter comes from this ServiceNow Known Error article
Regards,
Robin
- 4,354 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
So the nice folks at ServiceNow have provided a way to make the Variable Editor read-only in Kingston without any customization:
But based on my testing it seems that this doesn't work in Service Portal either.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
A solution for New York exists OOB. Clone the sp-variable-editor. Make sure you update your widget instance to point at the cloned widget.
Add an Option Schema as follows:
This will allow the code in the server script to execute
Alternately just put // an the beginning of the if statement in the server script (Not as elegant)
Optionally you can disable the save button as well by commenting out the c.showSave = true; line in the client script, or set it to false.
Hope this helps.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Has anything changed in let's say Vancouver version so the RITM variables on ServicePortal can be made editable or read-only as per the needs?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes, you can make the variable editor read-only for a particular Service Portal by adding a "readonly_variable_editor" property to the Quick start config field on the portal record as described in this article:
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I want to make it editable only when state is in "draft". how to make changes
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Are you using the new WashingtonDc / Xanadu feature for drafts?