Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

@devservicenow k I am sorry. i dont know the other options

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

Html:

 

Server :

 

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


data.incidents = [];
var inc = new GlideRecord("task_time_worked");
inc.addEncodedQuery("task.sys_class_name=sn_customerservice_task^ORtask.sys_class_name=sn_customerservice_case");
if(input && input.action=="keyword_search"){
inc.addQuery('123TEXTQUERY321', input.keyword);
}
inc.query();

while(inc.next()){
data.incidents.push({
"number": inc.task.number.toString(),
"accountName": inc.task.account.name.toString(),
"accountNumber": inc.task.account.number.toString()
});
}
})();

 

@jaheerhattiwale 

@devservicenow k 

I tried below code ,and it can work....(it seems

 that  123TEXTQUERY321 can works on reference field)

var gr = new GlideRecord('x_615438_test_cpux')
// field 'task_ref' references incident table
gr.addQuery('123TEXTQUERY321', 'INC0010016');
gr.query()
while(gr.next()){

    gs.info(gr.task_ref.number)

}

 

 

But i find that 123TEXTQUERY321  is not a good  function.

1 .  I tried other keywords such as short_description value of  the incident record, bug i can't get the correct result (in fact  nothing returns).

 

2.   123TEXTQUERY321  doesn't work like  "contain"... 

      "INC0010016" will get a result , but  "INC" will not..

      It can get a search on a word but can't search part of a word..

 

So , i suggest that  use "contains" with limited fields instead of "123TEXTQUERY321"

 

sample:

now_GR.addEncodedQuery("numberLIKEa^ORshort_descriptionLIKEb");

 

I'm not particularly sure of my conclusion,for reference only。

   

    

 

 

 

 

 

Please mark my answer as correct and helpful based on Impact.