Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Read Only Variables in a Variable Editor

ralvarez
Tera Guru

I've seen that many people have been asking how to set to read only all the variables within the variable editor of an incident or any other task.

The solution is to modify (or create) the Formatter that shows the variable editor, for instance "Incident Variable Editor".

This formatter is using an UI macro called "com_glideapp_questionset_default_question_editor". If we open it we see the following code:

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

      <g:requires name="scripts/js_includes_catalog.js" includes="true"/>

      <g:requires name="styles/${new CatalogCssSelector().getVariableCss()}" includes="true"/>

      <g2:render_component componentName="com.glideapp.questionset.DefaultQuestionEditor" />

</j:jelly>

We only need to add the following line before the g2:render_component, to have our variable editor in read only mode:

<j2:set var="jvar_questionset_read_only" value="true" />    

Here the result:

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

      <g:requires name="scripts/js_includes_catalog.js" includes="true"/>

      <g:requires name="styles/${new CatalogCssSelector().getVariableCss()}" includes="true"/>

      <j2:set var="jvar_questionset_read_only" value="true" />    

      <g2:render_component componentName="com.glideapp.questionset.DefaultQuestionEditor" />

</j:jelly>

I hope this solution helps you!

Cheers,

Roberto

5 REPLIES 5

Chuck Tomasi
Tera Patron

Hi Roberto,



Thank you for the quick and easy change.



Just a reminder to those who do are thinking about doing this, you are modifying an OOB UI macro that carries with it upgrade risks.


How can we do this for marketing request form.



Thanks,


Y Anjaneyulu


Hi ctomasi,



Is there a better way to do this? That is, to lock all variables shown in the Variable Editor formatter? I know this can be done with Catalog UI Policies, however that would require a policy per Catalog Item or Variable Set etc. I'm looking for a solution to lock down the Variable Editor and make it read only for all Requested Item forms regardless of which Catalog Item they are linked to.



Regards,


MotoMaximus
Kilo Contributor

Perfect!  Thank you!