The CreatorCon Call for Content is officially open! Get started here.

Search Option in My newely created Widget

devservicenow k
Tera Contributor

I Have created a new widget 0401a.jpg0401b.jpg in this widget i have added Filter Option using search option,

in that search option i need to filter option to select any task  , how to set that?

@jaheerhattiwale  can you help me in this one?

1 ACCEPTED SOLUTION

@devservicenow k Tried and tested 100% working solution.

 

HTML script:

<div>
<div class="search-icon">
<input ng-model="c.keyword" type="text" placeholder="Search..">
<button type="button" ng-click="c.keywordSearch()"><i class="fa fa-search"></i></button>
</div>

<table class="table">
<tr>
<th>Number</th>
<th>Short Description</th>
</tr>
<tr ng-repeat="inc in data.incidents">
<td>{{inc.number}}</td>
<td>{{inc.short_description}}</td>
</tr>
</table>
</div>

 

Client script:

api.controller=function() {
/* widget controller */
var c = this;

c.keywordSearch = function(){
c.data.action = "keyword_search";
c.data.keyword = c.keyword;
c.server.update().then(function(resp){

})
}
};

 

Server Script:

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */


data.incidents = [];
var inc = new GlideRecord("incident");
if(input && input.action=="keyword_search"){
inc.addQuery('123TEXTQUERY321', input.keyword);
}
inc.query();

while(inc.next()){
data.incidents.push({
"number": inc.number.toString(),
"short_description": inc.short_description.toString()
})
}
})();

 

 

Result:

Without search:

jaheerhattiwale_0-1672847215344.png

 

With search:

jaheerhattiwale_1-1672847244439.png

 

 

Note:

Replace the server side with your table and query

 

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

33 REPLIES 33

Bro in the continuation of the Above widet, they have given me next requirement like this.

"

We need a dedicated for this one two filter and based on that show results

Also there are many solutions online so use all of them for a try

Do leave any option

Try all"

what do i need to do ? @jaheerhattiwale 

@devservicenow k I did not understand the requirement regarding one or two filter.

 

And what are the ways if they tell the name we can research on it.

 

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

yeah but apart from search option filter which we used.

is there any other filter available for widgets? @jaheerhattiwale 

they are telling to add some more different type of filters

Using data table from url definition we can add the filters. Its best recommnended.

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

but for custom widget we need to create filters . for the task_time_worked table i need the other filters to be shown, because already we have shown form search option, 

please help me to show other filters for that scipt, as iam new to servicneow i dont know how to do that