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

Hi @Arjun Reddy Yer ,

Step 1: I would recommend keeping the variable editor formatter in the form section instead if creating the new one.

Step 2: Use onLoad client script to set the visibility of the section where you have the variables. already sample code to use is shared by Tim.

 

Please try the above and let us know the result. 

 

Please 

 


Thanks & Regards,
Vasanth

Hi @Vasantharajan N , @Tai Vu 

 

As off now it's working as expected but instead of Role condition based on User location or Company or to a particular Catalog item which is having Request Method as Incident can we get

 

<g2:evaluate var="is_visible" jelly="true">
	is_visible = gs.hasRole('admin');// User role (instead of role based on User location or Company or to a particular Catalog item which is having Request Method as Incident can we make it to work)
</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>

 

Hi @Arjun Reddy Yer 

In the g2:evaluate and at the is_visible line, you can write js script, using Servicenow object there or you can also call a function from a script include to do your own validation.

 

Just try to consider the first approach that is creating a specific section on the form to store the variable formatter. This way will be much easier and you also don't need to customize OOTB stuff.

 

Cheers,

Tai Vu

can you please help me what needs to be mention in the below script 

<g2:evaluate var="is_visible" jelly="true">
	is_visible = gs.hasRole('admin');// to a particular Catalog item which is having Request Method as Incident can we make it to work)
</g2:evaluate>

 

Hi @Arjun Reddy Yer 

Since I don't know your requirement so I couldn't give you the exact condition validation.

In general, you can use gs.getUser().getCompanyID() to retrieve the User Company and use current to get the field value of the current record as well.

Example.

<g2:evaluate var="is_visible" jelly="true">
	var is_visible = false;
	if(gs.hasRole('admin')){
		is_visible = true;
	}
	if(gs.getUser().getCompanyID() === '<your_company_sys_id>'){
		is_visible = true;
	}
	is_visible;
</g2:evaluate>

 

I'm not sure about Catalog item and Request Method as Incident that you've mentioned above, because from your screenshot it displays as the Incident record, it's not Requested item record.

 

Cheers,

Tai Vu