Control Check box visibility in an UI page

Bidisha Das
Tera Contributor

Hi All,

I have an UI page that appears on Incident form on click of "Resolve" button in form of a Dialog window.I have a checkbox in the UI page that needs to appear on basis of some conditions.

So, I already have the same checkbox field on form as well that is visible on basis of below condition -

Display BR -

var GSDGroups = [];
var GSDUsers = [];
var grGroups = new GlideRecord('sys_user_group');
grGroups.addQuery('name','CONTAINS','GSD');
grGroups.query();
while(grGroups.next()) {
GSDGroups.push(grGroups.sys_id+'');
}
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group','IN',GSDGroups);
gr.query();
while(gr.next()){
GSDUsers.push(gr.user.sys_id+'');
}

if(GSDUsers.toString().indexOf(current.opened_by)>-1) {
g_scratchpad.member = 'true';
}

I have a client script that is accessing the scratchpad value from the BR & hiding/showing the Check box on the form.

I need to know how do I achieve the same functionality in UI page as I can't use g_scratchpad there. Also where do I need to mention the condition in the UI page script?

Thanks in advance.

1 ACCEPTED SOLUTION

Hi Bidisha,

I tried the above script and found that the current is used in UI page. The current will not work in the UI page so you have to pass the current record through the glidemodal preference. And do the GlideRecord to get the opened by field of current record.

If not then if the field is available on the form (opened_by) then you can directly give the value of that form.

The below example I am passing the sysid of the record in UI page and there i am doing the gliderecord to get the opened by and then comparing.

Ui Action script: Passing the current record sysid

function test() {
  var dlg_usr = new GlideDialogWindow("test_ui_page");//UI page
       dlg_usr.setTitle('Confirmation');
    dlg_usr.setPreference("inc_id", g_form.getUniqueValue()); //Current incident record sysid
    dlg_usr.render();
}

 

UI Page script: Getting the Value of current record and doing gliderecod to fetch the opened by

<?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:evaluate var="jvar_visible" object="true">
var visible = 'false';
var GSDGroups = [];
var GSDUsers = [];

var grGroups = new GlideRecord('sys_user_group');
grGroups.addQuery('name','CONTAINS','catalog');
grGroups.query();
while(grGroups.next()) {
GSDGroups.push(grGroups.sys_id+'');
}
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group','IN',GSDGroups);
gr.query();
while(gr.next()){
GSDUsers.push(gr.user.sys_id+'');
}
		
		var inc_sys = RP.getWindowProperties().get('inc_id');
		var incgr = new GlideRecord('incident');
		incgr.get(inc_sy);
		var opendby = incgr.getValue('opened_by');

		
		
if(GSDUsers.toString().indexOf(opendby)>-1) {
visible= 'true';
}
visible;
</g:evaluate>

<j:if test="${jvar_visible == 'true'}">

<input id="checkbox" value="false" class="checkbox"  type="checkbox" name="checkbox"/>

</j:if>
	
	
	
</j:jelly>

This code will work 

 

Mark helpful and correct if it helps.

Thanks,

CB

View solution in original post

13 REPLIES 13

Hi Bidisha,

I tried the above script and found that the current is used in UI page. The current will not work in the UI page so you have to pass the current record through the glidemodal preference. And do the GlideRecord to get the opened by field of current record.

If not then if the field is available on the form (opened_by) then you can directly give the value of that form.

The below example I am passing the sysid of the record in UI page and there i am doing the gliderecord to get the opened by and then comparing.

Ui Action script: Passing the current record sysid

function test() {
  var dlg_usr = new GlideDialogWindow("test_ui_page");//UI page
       dlg_usr.setTitle('Confirmation');
    dlg_usr.setPreference("inc_id", g_form.getUniqueValue()); //Current incident record sysid
    dlg_usr.render();
}

 

UI Page script: Getting the Value of current record and doing gliderecod to fetch the opened by

<?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:evaluate var="jvar_visible" object="true">
var visible = 'false';
var GSDGroups = [];
var GSDUsers = [];

var grGroups = new GlideRecord('sys_user_group');
grGroups.addQuery('name','CONTAINS','catalog');
grGroups.query();
while(grGroups.next()) {
GSDGroups.push(grGroups.sys_id+'');
}
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group','IN',GSDGroups);
gr.query();
while(gr.next()){
GSDUsers.push(gr.user.sys_id+'');
}
		
		var inc_sys = RP.getWindowProperties().get('inc_id');
		var incgr = new GlideRecord('incident');
		incgr.get(inc_sy);
		var opendby = incgr.getValue('opened_by');

		
		
if(GSDUsers.toString().indexOf(opendby)>-1) {
visible= 'true';
}
visible;
</g:evaluate>

<j:if test="${jvar_visible == 'true'}">

<input id="checkbox" value="false" class="checkbox"  type="checkbox" name="checkbox"/>

</j:if>
	
	
	
</j:jelly>

This code will work 

 

Mark helpful and correct if it helps.

Thanks,

CB

Hi Bidisha,

In above ui page script one small typo mistake i did in the incgr. Instead of inc_sys I hae  used inc_sy in get method.

So Updated UI page script would be:

<?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:evaluate var="jvar_visible" object="true">
var visible = 'false';
var GSDGroups = [];
var GSDUsers = [];

var grGroups = new GlideRecord('sys_user_group');
grGroups.addQuery('name','CONTAINS','catalog');
grGroups.query();
while(grGroups.next()) {
GSDGroups.push(grGroups.sys_id+'');
}
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group','IN',GSDGroups);
gr.query();
while(gr.next()){
GSDUsers.push(gr.user.sys_id+'');
}
		
		var inc_sys = RP.getWindowProperties().get('inc_id');
		var incgr = new GlideRecord('incident');
		incgr.get(inc_sys);
		var opendby = incgr.getValue('opened_by');

		
		
if(GSDUsers.toString().indexOf(opendby)>-1) {
visible= 'true';
}
visible;
</g:evaluate>

<j:if test="${jvar_visible == 'true'}">

<input id="checkbox" value="false" class="checkbox"  type="checkbox" name="checkbox"/>

</j:if>
	
	
	
</j:jelly>

 

This script will work fine  and it will show the checkbox only if the opened by user is part of the groups and won't show the checkbox if the opened by user is not part of the group.

 

 

Mark helpful and correct if it helps.

Thanks,

CB

Thanks a lot CB. I will surely try your code & let you know if it worked for me.

Thank you so much. It worked perfectly.