How to show Incident Variable Editor on Incident form to a specific users

Arjun Reddy Yer
Tera Guru

How to show Incident Variable Editor to a specific users.

As the Variable Section on the incident form should be visible to specific users only.

As tried with OnLoad Client Script but it's not working.

Can anyone help me @Vasantharajan N 

 

Like below variable section should be visible only to specific Users

ArjunReddyYer_0-1705653458635.png

Client Script Used:

 

ArjunReddyYer_1-1705653525271.png

 

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @Arjun Reddy Yer 

From your screenshot, the Variables formatter is not yet under any Form Section.

You can create a new section for the Incident Variable Formatter, which is similar to below sections.

Screenshot 2024-01-19 at 16.59.15.png

Then use the API below to show and hide section accordingly.

setSectionDisplay(String sectionName, Boolean display)

 

In the other hand, you can consider to clone the Formatter for your own customization.

Name: Incident Variable Editor

URL: https://<instance_name>/sys_ui_formatter.do?sys_id=710bb6ba0a0a0b0100ba712aa4b9f048

 

The Formatter above calls to an UI Macro named: com_glideapp_questionset_default_question_editor

Clone to the new one and apply specific conditions to display it. Sample below

<g2:evaluate var="is_visible" jelly="true">
	is_visible = gs.hasRole('admin');
</g2:evaluate>

<div data-sn-macro-sys-id="${jvar_macro_sys_id}">
	<j2:if test="$[is_visible]">
		<j2:if test="$[jvar_catalog_item != '']">
			<j2:set var="jvar_producer_target_record" value="true"/>
			<g2:client_script type="catalog_question_editor" catalogItem="$[jvar_catalog_item]"/>
			<g:inline template="catalog_ui_policy.xml"/>
			<g2:render_component componentName="com.glideapp.servicecatalog.DefaultQuestionEditor"/>
		</j2:if>
		<j2:if test="$[jvar_catalog_item == '']">
			<!--Render old default editor if catalog item is not found -->
			<g2:render_component componentName="com.glideapp.questionset.DefaultQuestionEditor"/>
		</j2:if>
	</j2:if>
</div>

 

Cheers,

Tai Vu

View solution in original post

13 REPLIES 13

Markus9
Tera Contributor

You could create a Read ACL for "incident.variables" so that only people who fulfill this ACL are allowed to read the variables.

Harish KM
Kilo Patron
Kilo Patron

Hi @Arjun Reddy Yer I think the issue is with your if condition, Can you keep alert inside your if and check whether the if condition is executing?

Regards
Harish

Tai Vu
Kilo Patron
Kilo Patron

Hi @Arjun Reddy Yer 

From your screenshot, the Variables formatter is not yet under any Form Section.

You can create a new section for the Incident Variable Formatter, which is similar to below sections.

Screenshot 2024-01-19 at 16.59.15.png

Then use the API below to show and hide section accordingly.

setSectionDisplay(String sectionName, Boolean display)

 

In the other hand, you can consider to clone the Formatter for your own customization.

Name: Incident Variable Editor

URL: https://<instance_name>/sys_ui_formatter.do?sys_id=710bb6ba0a0a0b0100ba712aa4b9f048

 

The Formatter above calls to an UI Macro named: com_glideapp_questionset_default_question_editor

Clone to the new one and apply specific conditions to display it. Sample below

<g2:evaluate var="is_visible" jelly="true">
	is_visible = gs.hasRole('admin');
</g2:evaluate>

<div data-sn-macro-sys-id="${jvar_macro_sys_id}">
	<j2:if test="$[is_visible]">
		<j2:if test="$[jvar_catalog_item != '']">
			<j2:set var="jvar_producer_target_record" value="true"/>
			<g2:client_script type="catalog_question_editor" catalogItem="$[jvar_catalog_item]"/>
			<g:inline template="catalog_ui_policy.xml"/>
			<g2:render_component componentName="com.glideapp.servicecatalog.DefaultQuestionEditor"/>
		</j2:if>
		<j2:if test="$[jvar_catalog_item == '']">
			<!--Render old default editor if catalog item is not found -->
			<g2:render_component componentName="com.glideapp.questionset.DefaultQuestionEditor"/>
		</j2:if>
	</j2:if>
</div>

 

Cheers,

Tai Vu

Hi @Tai Vu ,

 

Created new Incident Variable Editor and created new UI Macro based on below script but it's not working.

The thing is the Variables on the incident for is to be visible only for the users who has specific role.

UI Formatter: Incident Variable Editor for AU

UI Macro: com_glideapp_questionset_default_question_editor_for_australia

<?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"/>
    <g:if_polaris>
       <g:then>
         <g:requires name="styles/${new CatalogCssSelector().getPolarisVariableCss()}" includes="true"/>
      </g:then>
    </g:if_polaris>
    <g2:evaluate var="jvar_catalog_item">
       function eval_cat_item() {
        var cat_item = "";
var catItemProducedGr = new GlideRecord("sc_item_produced_record");
catItemProducedGr.addQuery("record_key", current.getUniqueValue());
catItemProducedGr.query();
if (catItemProducedGr.next())
cat_item = catItemProducedGr.getValue("producer");
        return cat_item;
       }
       eval_cat_item();
    </g2:evaluate>
<!-- load only the one_to_one variable sets -->
    <g2:evaluate var="jvar_cat_sets" jelly="true">
       var jvar_cat_sets = "";
       var gr = new GlideRecord("io_set_item");
       gr.addQuery("sc_cat_item", jelly.jvar_catalog_item);
   gr.addQuery("variable_set.type", "one_to_one");
       gr.query();
       while (gr.next()) {
          if (jvar_cat_sets.length > 0)
             jvar_cat_sets += ",";
          jvar_cat_sets += gr.variable_set;
       }
       jvar_cat_sets;
    </g2:evaluate>
<g2:evaluate var="is_visible" jelly="true">
is_visible = gs.hasRole('Australia User');// Users having this role
</g2:evaluate>
<div data-sn-macro-sys-id="${jvar_macro_sys_id}">
<j2:if test="$[is_visible]">
<j2:if test="$[jvar_catalog_item != '']">
<j2:set var="jvar_producer_target_record" value="true"/>
<g2:client_script type="catalog_question_editor" catalogItem="$[jvar_catalog_item]"/>
<g:inline template="catalog_ui_policy.xml"/>
<g2:render_component componentName="com.glideapp.servicecatalog.DefaultQuestionEditor"/>
</j2:if>
<j2:if test="$[jvar_catalog_item == '']">
<!--Render old default editor if catalog item is not found -->
<g2:render_component componentName="com.glideapp.questionset.DefaultQuestionEditor"/>
</j2:if>
</j2:if>
</div>
</j:jelly>

it's still visible to all the users who is not having the role. @Vasantharajan N