- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2024 03:38 AM
Hi Team,
I have created a dashboard and reports on the user table and I want to add interactive filters for the name field on the user table but there is no interactive field for the string type field.
I need to create a custom interactive filter for the name field on the user table so we can search any record from the user name.
I want to include the condition active is true
I am not sure how to write code can someone help me?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2024 07:03 AM
Add Following code:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div class="row" style="margin-left:10px; margin-right:10px">
<div class="col-md-3" style='width:330px'>
<p style="font-size:15px"><b>User Name</b></p>
<input id='user_name' type = "text" onchange='filterUser()' ></input>
</div>
</div>
<script>
var dbh = new DashboardMessageHandler("filter_tasktype");
function filterUser(){
var userName = $j('#user_name').val();
var filter_message = {};
filter_message.id = "taskFilter"
filter_message.table = "sys_user"
if ((userName != '' )) {
filter_message.filter = "nameLIKE"+userName;
SNC.canvas.interactiveFilters.setDefaultValue({
id: filter_message.id,
filters: [filter_message]
}, false);
dbh.publishFilter(filter_message.table, filter_message.filter);
}
else {
filter_message.filter = "";
SNC.canvas.interactiveFilters.setDefaultValue({
id: filter_message.id,
filters: [filter_message]
}, false);
dbh.removeFilter();
}
}
</script>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2024 04:11 AM
Hi @lucky24
Might be helpful
https://www.process.st/how-to/add-interactive-filters-in-servicenow-dashboard/
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2024 05:15 AM - edited ‎02-05-2024 05:33 AM
Hello @lucky24 ,
-Create dynamic content and add following code :
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div class="row" style="margin-left:10px; margin-right:10px">
<div class="col-md-3" style='width:330px'>
<p style="font-size:15px"><b>User Name</b></p>
<input id='user_name' type = "text" onchange='filterUser()' ></input>
</div>
</div>
<script>
var dbh = new DashboardMessageHandler("filter_tasktype");
function filterUser(){
var userName = $j('#user_name').val();
var filter_message = {};
filter_message.id = "taskFilter"
filter_message.table = "sys_user"
if ((userName != '' )) {
filter_message.filter = "name="+userName;
SNC.canvas.interactiveFilters.setDefaultValue({
id: filter_message.id,
filters: [filter_message]
}, false);
dbh.publishFilter(filter_message.table, filter_message.filter);
}
else {
filter_message.filter = "";
SNC.canvas.interactiveFilters.setDefaultValue({
id: filter_message.id,
filters: [filter_message]
}, false);
dbh.removeFilter();
}
}
</script>
</j:jelly>
-In the dashboard, it will look like this:
If you have any questions, please let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2024 06:06 AM
Hi @Unique45
Thanks for the reply I tried with your suggestion and It's working fine.
If I want to add contain in the user name condition where do I need to change in the above code
For example - If I write 3 words in the name it should show all names that include these 3 words,
Can I do like this?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2024 07:03 AM
Add Following code:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div class="row" style="margin-left:10px; margin-right:10px">
<div class="col-md-3" style='width:330px'>
<p style="font-size:15px"><b>User Name</b></p>
<input id='user_name' type = "text" onchange='filterUser()' ></input>
</div>
</div>
<script>
var dbh = new DashboardMessageHandler("filter_tasktype");
function filterUser(){
var userName = $j('#user_name').val();
var filter_message = {};
filter_message.id = "taskFilter"
filter_message.table = "sys_user"
if ((userName != '' )) {
filter_message.filter = "nameLIKE"+userName;
SNC.canvas.interactiveFilters.setDefaultValue({
id: filter_message.id,
filters: [filter_message]
}, false);
dbh.publishFilter(filter_message.table, filter_message.filter);
}
else {
filter_message.filter = "";
SNC.canvas.interactiveFilters.setDefaultValue({
id: filter_message.id,
filters: [filter_message]
}, false);
dbh.removeFilter();
}
}
</script>
</j:jelly>