- 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 08:17 AM
Hi,
this should be handled via <g:evaluate> tag in HTML Section
You can use server side script in the <g:evaluate> tag
Then use the object in <j:if> tag to show/hide the checkbox
HTML Section:
<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>
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 09:02 AM
Hi Ankur,
Thanks for your response.
However, I did use the same script which you posted but it's not allowing me to save the script in the UI page, not sure what is going wrong, could be some HTML tags or the script that I am using inside the evaluate tag.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2020 09:18 AM
Hi Ankur,
Thanks for your response however it's never showing the Check box inspite of the condition being satisfied. Probably, it's never going inside the 'if' condition, not sure why, do I need to write something in the Client script part of the UI page?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2020 09:29 AM
Hi,
please share your code?
Are you saying based on the condition the checkbox should be visible/hidden on UI page?
What you are trying to achieve please explain?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader