- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2020 04:12 AM
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.
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2020 11:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2020 09:45 AM
Yes Ankur, you are correct.
I am trying to show the check box if this condition - GSDUsers.toString().indexOf(current.opened_by)>-1 suffices. So, whenever the script inside the 'evaluate' tag executes & the condition proves to be true, the checkbox should be visible else it should be hidden.
I have used the same code which you posted because this piece of code is working fine for me in the BR & client script which I am using on the incident form.
I even tried with the below inside the 'if' statement in the HTML but with no success-
<label>
<g2:ui_checkbox id="checkbox_id" name="check_box" value="false" />
<b>Could the Service Desk have resolved this?</b>
</label>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2020 09:59 AM
Hi,
you are using <g2:ui_checkbox> which is phase2 jelly tag
So you need to use phase 2 tag for <g2:evaluate>, <j2:if> and also during comparison use [] and not {}
so please update code as below
<g2:evaluate var="jvar_visible" object="true">
var visible = 'false';
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) {
visible= 'true';
}
visible;
</g2:evaluate>
<j2:if test="$[jvar_visible == 'true']">
<label>
<g2:ui_checkbox id="checkbox_id" name="check_box" value="false" />
<b>Could the Service Desk have resolved this?</b>
</label>
</j2:if>
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2020 10:27 AM
Hi Ankur,
It's still not working with phase2 jelly 'g2' tag.
However I even tried the first code of yours as below, still not working, not sure what is going wrong, please help me figure this out.
<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','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) {
visible= 'true';
}
visible;
</g:evaluate>
<j:if test="${jvar_visible == 'true'}">
<input id="checkbox" value="false" class="checkbox" disabled="disabled" type="checkbox" name="checkbox"/>
</j:if>
This is also never showing me the checkbox even if the condition suffices.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2020 12:55 AM
Hi,
I could see you are using current object so that won't work directly
you need to send the current record sys_id to UI page and then query and get opened_by
Update Script below and it should work
Place this line to send sys id from where you are calling UI page
dialog.setPreference("sys_id", g_form.getUniqueValue());
HTML: highlighted in bold is the new code
<j2:set var="jvar_sys_id" value="$[RP.getWindowProperties().get('sys_id')]"/>
<g2:evaluate var="jvar_visible" object="true" jelly="true">
var visible = 'false';
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+'');
}
var sys_id = jelly.jvar_sys_id;
var tableRec = new GlideRecord('incident');
tableRec.get(sys_id);
if(GSDUsers.toString().indexOf(tableRec.opened_by)>-1) {
visible= 'true';
}
visible;
</g2:evaluate>
<j2:if test="$[jvar_visible == 'true']">
<label>
<g2:ui_checkbox id="checkbox_id" name="check_box" value="false" />
<b>Could the Service Desk have resolved this?</b>
</label>
</j2:if>
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2020 11:14 AM
Hi Ankur,
Please let me know if my evaluate script is correct? I know it works fine in BR but not sure if it's going to work the same way inside the jelly tags.I am not all good in jelly scripts, so really need your help.
I have tried with both the scripts which you have posted here without changing anything but still the checkbox is never visible even after the condition inside the 'if' statement is true.