Custom Interactive Filter - Get Value selected in dropdown
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2024 04:02 AM
Hi All,
I have created a Custom Interactive filter for displaying Region values from User table, the requirement is to create use this as Level 1 filter and have Location values as Level 2 filter. I am trying to display location dropdown values based on "Region" selected and need help with Jelly code to get value selected under "Region" dropdown.
Any experts in Jelly script, please help.
Thanks,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 03:28 AM - edited 07-05-2024 03:29 AM
Hello @sivaranjani3894 ,
Please refer below code as a example and update it as per your requirement:
Jelly code:
<j:jelly xmlns:j="jelly:core" xmlns:g="jelly:com.glide.ui.tags">
<g:ui_page>
<g:ui_section>
<table>
<tr>
<td>Region:</td>
<td>
<select id="regionSelect" onchange="updateLocations()">
<option value="">--Select Region--</option>
<g:query table="sys_user" order_by="region">
<g:if test="region != ''">
<option value="${region}">${region}</option>
</g:if>
</g:query>
</select>
</td>
</tr>
<tr>
<td>Location:</td>
<td>
<select id="locationSelect">
<option value="">--Select Location--</option>
</select>
</td>
</tr>
</table>
</g:ui_section>
</g:ui_page>
</j:jelly>
Client side script:
function updateLocations() {
var region = document.getElementById('regionSelect').value;
var locationSelect = document.getElementById('locationSelect');
// Clear existing options
locationSelect.innerHTML = '<option value="">--Select Location--</option>';
// Make an AJAX call to get locations based on the selected region
if (region) {
var ga = new GlideAjax('GetLocations');
ga.addParam('sysparm_name', 'getLocationsByRegion');
ga.addParam('sysparm_region', region);
ga.getXMLAnswer(function(response) {
var locations = JSON.parse(response);
locations.forEach(function(location) {
var option = document.createElement('option');
option.value = location.sys_id;
option.text = location.name;
locationSelect.add(option);
});
});
}
}
Script include:
var GetLocations = Class.create();
GetLocations.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLocationsByRegion: function() {
var region = this.getParameter('sysparm_region');
var locations = [];
if (region) {
var locationGR = new GlideRecord('cmn_location');
locationGR.addQuery('region', region);
locationGR.query();
while (locationGR.next()) {
locations.push({
sys_id: locationGR.getUniqueValue(),
name: locationGR.getValue('name')
});
}
}
return new JSON().encode(locations);
}
});
Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!
Thank you!!
Dnyaneshwaree Satpute
Tera Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 09:58 PM
Hi @Dnyaneshwaree ,
Thanks for your response. I used the following code and it is working as expected.
My Custom Interactive Filter looks like:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 10:00 PM
Above code will render 2 fields on your Dashboard "Region" and "Location" and filter your reports based on the values selected.