Search Source configured to find a specific field on my incident table

Domenic
Kilo Explorer

I am trying to allow my users to perform a search on a specific field and get all results that have that searched for field.

For example I have a store which has a store number (123). I want my users to be able to bring up the search page in my portal and enter store #123 and the results will be all incidents for store #123.

I have already created a search source specifically for my incident table.

 

Domenic

4 REPLIES 4

Mike Patel
Tera Sage

you can create new search source for portal with data fetch script something like

 

(function(query) {
var results = [];
/* Calculate your results here. */
if (!gs.isLoggedIn())
return results;

var inc = new GlideRecord('incident');
inc .addEncodedQuery('u_storeLIKE'+query);
inc .query();
var catCount = 0;
while (inc.next() && catCount < data.limit) {
if (!$sp.canReadRecord(inc))
continue;
var item = {};
item.type = "inc";
item.page = "ticket";

$sp.getRecordDisplayValues(item, inc, 'number,short_description,sys_id');
item.label = item.number;
item.primary = item.number;
results.push(item);
catCount++;
}
return results;
})(query);

Domenic
Kilo Explorer

I am not a developer so please forgive the questions. Where do I insert the incident table parameter I am searching and the field?

The field that I want the search to be based on is u_store_location

find_real_file.png

Domenic
Kilo Explorer

I inserted the code into the script source and changed one parameter which is in BOLD and Underlined.

However I am still not getting back results for the store number I entered on my search. Instead now I am getting random incident tickets and when I click the link to go to the ticket my next screen is blank.

(function(query) {
var results = [];
/* Calculate your results here. */
if (!gs.isLoggedIn())
return results;

var inc = new GlideRecord('incident');
inc .addEncodedQuery('incident.u_store_location'+query);
inc .query();
var catCount = 0;
while (inc.next() && catCount < data.limit) {
if (!$sp.canReadRecord(inc))
continue;
var item = {};
item.type = "inc";
item.page = "ticket";

$sp.getRecordDisplayValues(item, inc, 'number,short_description,sys_id');
item.label = item.number;
item.primary = item.number;
results.push(item);
catCount++;
}
return results;
})(query);