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

xiaix
Tera Guru

Very nice.. thanks!