Robin Hearne
Tera Expert

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

  1. Clone the 'sp-variable-editor' widget (I called mine sp-variable-viewer')
  2. 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);
}
  1. 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

Comments
Robin Hearne
Tera Expert

So the nice folks at ServiceNow have provided a way to make the Variable Editor read-only in Kingston without any customization:

https://docs.servicenow.com/bundle/kingston-it-service-management/page/product/service-catalog-manag...

But based on my testing it seems that this doesn't work in Service Portal either.

Eric Johansson
Mega Guru

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:

find_real_file.png

This will allow the code in the server script to execute

find_real_file.png

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.

AJ2025
Tera Contributor

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?

Robin Hearne
Tera Expert

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:

https://docs.servicenow.com/bundle/xanadu-servicenow-platform/page/product/service-catalog-managemen...

 

Hafsa1
Mega Sage

I want to make it editable only when state is in "draft". how to make changes

Robin Hearne1
Tera Contributor

Are you using the new WashingtonDc / Xanadu feature for drafts?  

https://www.servicenow.com/docs/bundle/xanadu-servicenow-platform/page/product/service-catalog-manag... 

Version history
Last update:
‎08-01-2018 04:04 PM
Updated by: