Using string field as yes/no field for interactive filter
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 11:12 PM
Hi,
I have a field called count which is basically a string value field and I need to create an interactive filter where if count is greater than 0 then it should show "yes" and if 0 then it should show "no" in the option in interactive filter choice. I don't have much experience in jelly scripting . Is there any other way achieve this? Or what jelly scripting should be used in this case.
Regards,
Maharshi
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 10:55 PM
Hello @Maharshi Chatte ,
Try below code it might be help you:
Script include:
var CountFilter = Class.create();
CountFilter.prototype = {
initialize: function() {
},
getFilterOptions: function() {
var result = [];
var gr = new GlideRecord('your_table'); // Replace 'your_table' with your table name
gr.query();
while (gr.next()) {
var countValue = parseInt(gr.getValue('count')); // Assuming 'count' is the field name
if (countValue > 0) {
result.push('yes');
} else {
result.push('no');
}
}
return JSON.stringify(result);
},
type: 'CountFilter'
};
Client script:
function onLoad() {
var ga = new GlideAjax('CountFilter');
ga.addParam('sysparm_name', 'getFilterOptions');
ga.getXMLAnswer(function(response) {
var options = JSON.parse(response);
var filterField = g_form.getControl('your_filter_field'); // Replace 'your_filter_field' with your filter field name
// Clear existing options
while (filterField.options.length > 0) {
filterField.remove(0);
}
// Add new options
options.forEach(function(option) {
var opt = new Option(option, option);
filterField.options.add(opt);
});
});
}
Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!
Dnyaneshwaree Satpute
Tera Guru
Thank you!!
Dnyaneshwaree Satpute
Tera Guru