How to add filters for the Widgets

devservicenow k
Tera Contributor

I have Created a Widget with the Filter option using Search option .0601c.jpg

 

and the HTML and server script is working fine

 

and the Records is searched easily by search option0901b.jpg

 

Now i need to Add one more Filter in that Widget 0901a.jpg

like the marked one i need the Filter in the widget.

in the View Filter instead of Closed Request i need case records/case task records .

how to do that can anyone help me.

@jaheerhattiwale 

 

 

1 ACCEPTED SOLUTION

jaheerhattiwale
Mega Sage
Mega Sage

@devservicenow k Add the below code to exiting widget.

 

HTML:

<sn-choice-list
field="c.mychoice"
sn-model="c.mychoice"
sn-options="c.mychoicelistoption"
sn-value-field="myChoiceValue"
sn-text-field="myChoiceDisplay"
sn-items="c.mychoiceoptions"
sn-on-change="c.changeClass(selectedValue)">
</sn-choice-list>

 

Client controller:

c.mychoiceoptions = [
{
myChoiceDisplay:"All",
myChoiceValue:"all"
},
{
myChoiceDisplay:"Case records",
myChoiceValue:"case_records"
},
{
myChoiceDisplay:"Case tasks",
myChoiceValue: "case_tasks"
}
];

c.mychoicelistoption = {
hideSearch: true
};

c.mychoice = "all";

c.changeClass = function(taskType){
c.data.action = "change_class";
c.data.taskType = taskType;
c.server.update();
}

 

Server script:

if(input && input.action=="change_class"){
if(input.taskType == "all"){
inc.addEncodedQuery("task.sys_class_name=sn_customerservice_task^ORtask.sys_class_name=sn_customerservice_case");
}else if(input.taskType == "case_records"){
inc.addEncodedQuery("task.sys_class_name=sn_customerservice_case");
}else if(input.taskType == "case_tasks"){
inc.addEncodedQuery("task.sys_class_name=sn_customerservice_task");
}
}

 

 

jaheerhattiwale_0-1673263379930.png

 

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

6 REPLIES 6

jaheerhattiwale
Mega Sage
Mega Sage

@devservicenow k Add the below code to exiting widget.

 

HTML:

<sn-choice-list
field="c.mychoice"
sn-model="c.mychoice"
sn-options="c.mychoicelistoption"
sn-value-field="myChoiceValue"
sn-text-field="myChoiceDisplay"
sn-items="c.mychoiceoptions"
sn-on-change="c.changeClass(selectedValue)">
</sn-choice-list>

 

Client controller:

c.mychoiceoptions = [
{
myChoiceDisplay:"All",
myChoiceValue:"all"
},
{
myChoiceDisplay:"Case records",
myChoiceValue:"case_records"
},
{
myChoiceDisplay:"Case tasks",
myChoiceValue: "case_tasks"
}
];

c.mychoicelistoption = {
hideSearch: true
};

c.mychoice = "all";

c.changeClass = function(taskType){
c.data.action = "change_class";
c.data.taskType = taskType;
c.server.update();
}

 

Server script:

if(input && input.action=="change_class"){
if(input.taskType == "all"){
inc.addEncodedQuery("task.sys_class_name=sn_customerservice_task^ORtask.sys_class_name=sn_customerservice_case");
}else if(input.taskType == "case_records"){
inc.addEncodedQuery("task.sys_class_name=sn_customerservice_case");
}else if(input.taskType == "case_tasks"){
inc.addEncodedQuery("task.sys_class_name=sn_customerservice_task");
}
}

 

 

jaheerhattiwale_0-1673263379930.png

 

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

yeah i have tried on Loading the sp portals, when we click on that filter it is displaying 

no records found0901c.jpg

@devservicenow k Send the screenshot of code

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

this is the code 0901c.jpg