UI Page submission - how can processing script access the dynamic ui_checkbox values submitted from ui_form?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2020 07:59 PM
I have a basic UI page that is just a sandbox to prove a concept I want to do. Basically, the UI Page is invoked through a UI Action (from cmdb_ci_computer) by way of a GlideModal. The UI Page queries the cmdb_ci_computer table and shows a list 5 other computer records as ui_checkbox elements. The user can then select up to 5 of the computer checkboxes and submit the form. I then want to be able to have my server side processing script be able to access these dynamic elements that were submitted with the form (i.e., I do not want to simply hard code a name or value for these checkboxes as they come from the query ran).
How does my processing script get access to these dynamic checkboxes and be able to tell 1) which ones are selected and 2) what the values and / or names were submitted as "checked?" I've provided my HTML and processing script below. I've ready through the SNOW UI page documentation and I cannot find anywhere that describes how to do this. Any help is greatly appreciated.
HTML
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<style>
.header-img {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
<!-- Jelly Phase 2 getting data -->
<g2:evaluate>
var gr = new GlideRecordSecure("cmdb_ci_computer");
gr.setLimit(5);
gr.query();
</g2:evaluate>
<g:ui_form>
<h4>Select one or more computers to update. These are dynamic values.</h4>
<table>
<j2:while test="$[gr.next()]">
<tr>
<td nowrap="true">
<label>$[gr.getValue('name')]</label>
</td>
<td>
<g2:ui_checkbox name="$[gr.getValue('sys_id')]" value="$[gr.getValue('sys_id')]" class="eBridgeDynamicFixlets" />
</td>
</tr>
</j2:while>
</table>
<g:dialog_buttons_ok_cancel ok="return true" cancel="return cancelClicked()" />
<input type="hidden" name="computer_sys_id" value="${sysparm_sys_id}" />
</g:ui_form>
</j:jelly>
Server Side Processing script from UI Page:
gs.info(“computer_sys_id comes across fine. : " + computer_sys_id);
// I cannot get dynamic checkboxes. I tried running exact same query on server side but
// var gr = new GlideRecordSecure("cmdb_ci_computer");
// gr.setLimit(5);
// gr.query();
// while (gr.next()) {
// gs.info("request param: " + gr.getValue("sys_id"));
// }
var uri = 'cmdb_ci_computer.do?sys_id=' + computer_sys_id;
response.sendRedirect(uri);
This is less relevant but shows my UI Action script on how my dialog is invoked from cmdb_ci_computer record:
Onclick: runSandboxDialog()
function runSandboxDialog() {
var gm = new GlideModal('x_my_scope_app_sandbox', false, 500);
gm.setTitle('My Sandbox');
gm.setPreference('sysparm_sys_id', g_form.getUniqueValue());
//Opens the dialog
gm.render();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2020 12:30 AM
Hi,
Since you are using checkbox functionality using g: tag possibly you can try calling onchange function which would set the value selected in the hidden html element and use that in processing script
something like this
HTML:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<style>
.header-img {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
<!-- Jelly Phase 2 getting data -->
<g2:evaluate>
var gr = new GlideRecordSecure("cmdb_ci_computer");
gr.setLimit(5);
gr.query();
</g2:evaluate>
<g:ui_form>
<h4>Select one or more computers to update. These are dynamic values.</h4>
<table>
<j2:while test="$[gr.next()]">
<tr>
<td nowrap="true">
<label>$[gr.getValue('name')]</label>
</td>
<td>
<g2:ui_checkbox name="$[gr.getValue('sys_id')]" value="$[gr.getValue('sys_id')]" class="eBridgeDynamicFixlets" />
</td>
</tr>
</j2:while>
</table>
<g:dialog_buttons_ok_cancel ok="return true" cancel="return cancelClicked()" />
<input type="hidden" name="computer_sys_id" value="${sysparm_sys_id}" />
<input type="hidden" name="checkboxvalue" id="checkboxvalue" value="" />
</g:ui_form>
</j:jelly>
Client Script:
function setCheckBox(element) {
var value = element.name;
value = value.substring(value.indexOf('ni') + 3, value.length);
document.getElementById('checkboxvalue').value = value;
}
Processing Script:
gs.info(“checbox value is : " + checkboxvalue);
Also check below links; it says how to use checkbox in UI pages and how to get values of those
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
02-11-2020 05:42 AM
Hi Ankur, thank you for the response. Unfortunately that won't work because that doesn't handle my "dynamic" data. For example, currently you see that my simple query is forced to 5 computer records. That is just for testing. My real solution will be a query that will get unknown number of records (although it will be fairly small). I cannot possibly know ahead of time how many hidden elements to add and then know the names/values of those on the server side processing script.
I need to find another solution that will allow a dynamic list of records to display as checkboxes and then have my processing script be able to iterate over the checked ones to take some action.
I also followed the links you provided (again thank you) and none of them are answering my goal. I do appreciate your time though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2020 07:35 PM
Helpful, thank you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2021 04:44 AM
I did something similar but gave each field a unique ID in numeric order then in the processing script I looped all rows getting their values with:
var rowid = row + i;
var getValue = request.getValue(rowid);