- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2019 11:06 PM
Hi All,
I am building a table of service providers that I want to make searchable for our users with some dynamic scripting. Normally I would use the filter in list view but I want to try a different approach to make it more user friendly and would love some advice and discussion as to whether this is actually possible.
Current method is to edit the list filter, and I would type the below filters to get what I'm after:
The method I am trying to create ideally is a UI action on the list view which prompts you for the type of provider, their business state, and what scope you are searching for. The system then runs a query on the table for this list, then applies the filter (probably redirecting to a new URL). A few of our users aren't tech savvy and it's a struggle for them to just wrap their head around the interface, hence why I'm trying this "foolproof" approach.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2019 09:01 PM
I have figured out the solution, and will post here as an FYI for anyone in the future that has a similar request.
I have created a choice field which is added to the list view, the default value is "double click here to apply filter" and the second option is "click here then click save" to trigger the onCellEdit client script.
script include:
getScopes: function(){
var scope = this.getParameter('sysparm_scope');
var gr = new GlideRecord('u_al_list');
gr.addQuery('u_table', 'Vendor SP Scope');
gr.addQuery('u_name', 'CONTAINS', scope);
gr.query();
var list = '';
while(gr.next()){
if(list == '') list = '%255Eu_scope_of_worksLIKE' + gr.getUniqueValue();
else list += '%255EORu_scope_of_worksLIKE' + gr.getUniqueValue();
}
return list;
},
Client Script:
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var type = '';
var service = '';
while (type != 'Service Provider' && type != 'Product Provider' && type != null){
type = prompt('Which type of vendor are you searching for? (Type "Service" or "Product")');
type += ' Provider';
}
if(type == 'Service Provider'){
var region = prompt('Enter the state or country you wish to locate a vendor in (eg NSW, Australia)');
service = prompt("Enter the type of service you are looking for (eg cleaning, maintenance, carpet, glass)");
var gax = new GlideAjax('AL_checkUserGroup');
gax.addParam('sysparm_name','getScopes');
gax.addParam('sysparm_scope',service);
gax.getXML(reloadPage);
} else if(type == 'Product Provider'){
service = prompt("Enter the type of product you are looking for");
//prompts and glideAjax to develop url for PP
}
function reloadPage(response){
var list = response.responseXML.documentElement.getAttribute("answer");
//alert("Searching for a " + type + " in " + region + " who performs " + service + ". Found " + list + " results");
top.window.location.replace("https://instance.service-now.com/nav_to.do?uri=%2Fu_vendor_list_list.do%3Fsysparm_offset%3D%26sysparm_query%3Du_provider_type%253D" + type + "%255Eu_business_addressLIKE" + region + list + "%26sysparm_list_mode%3Dgrid");
}
callback(false);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2019 12:34 AM
Hello,
I am not clear about your requirement. But I guess you are trying to make a custom filter.
If you want to combine multiple conditions and create one filter, follow the below steps.
Ex, you want to find some incidents with:
'Priority is Critical', 'Active is True', 'State is In Progress'
1. Create a custom filter.
Now, you can easily get the all conditions in one. You can see the below incidents.
Please mark Correct/Helpful. It it fulfill your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2019 10:24 PM
I am not trying to create pre-set filters, I am actually trying to give the users prompts to type the parameters they want to search by, then reload the page with a new URL containing the search parameters.
This is the onCellEdit client script I have created, in which a cell in the list view is edited to then trigger the a few prompt windows, before reloading the page. I actually have the onCellEdit script working without the GlideAjax (ie hardcoding the scopes), am I misusing the getXMLWait() function in this? There is an error message that appears but it doesn't have a message in it
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var type = '';
while (type != 'Service' && type != 'Product'){
type = prompt('Which type of vendor are you searching for? (Type "Service" or "Product")');
} if(type == 'Service'){
type += ' Provider';
var region = prompt('Enter the state you wish to locate a vendor in (eg NSW, QLD, VIC)');
var service = prompt("Enter the type of service you are looking for");
alert("running GlideAjax");
var gax = new GlideAjax('AL_checkUserGroup');
gax.addParam('sysparm_name','getScopes');
gax.addParam('sysparm_scope',service);
gax.getXMLWait();
var list = gax.getAnswer();
alert("Searching for a " + type + " in " + region + " who performs " + service + ". Found " + list.length + " results");
urlList = '';
for (var sc = 0; sc < list.length; sc++){
urlList += '%255EORu_scope_of_worksLIKE' + list[sc];
}
top.window.location.replace("https://instance.service-now.com/nav_to.do?uri=%2Fu_vendor_list_list.do%3Fsysparm_offset%3D%26sysparm_query%3Du_provider_type%253D" + type + "%255Eu_business_addressLIKE" + region + "%255Eu_scope_of_worksLIKEnull" + urlList + '%26sysparm_list_mode%3Dgrid');
}
callback(false);
}
getScopes: function(){
var scope = this.getParameter('sysparm_scope');
var gr = new GlideRecord('u_al_list');
gr.addQuery('u_table', 'Vendor SP Scope');
gr.addQuery('u_name', scope);
gr.query();
var list = '';
while(gr.next()){
if(list != '') list += ',';
list += gr.getUniqueValue();
}
gs.addInfoMessage('List found: ' + list);
return list;
},
error:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2019 09:01 PM
I have figured out the solution, and will post here as an FYI for anyone in the future that has a similar request.
I have created a choice field which is added to the list view, the default value is "double click here to apply filter" and the second option is "click here then click save" to trigger the onCellEdit client script.
script include:
getScopes: function(){
var scope = this.getParameter('sysparm_scope');
var gr = new GlideRecord('u_al_list');
gr.addQuery('u_table', 'Vendor SP Scope');
gr.addQuery('u_name', 'CONTAINS', scope);
gr.query();
var list = '';
while(gr.next()){
if(list == '') list = '%255Eu_scope_of_worksLIKE' + gr.getUniqueValue();
else list += '%255EORu_scope_of_worksLIKE' + gr.getUniqueValue();
}
return list;
},
Client Script:
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
var type = '';
var service = '';
while (type != 'Service Provider' && type != 'Product Provider' && type != null){
type = prompt('Which type of vendor are you searching for? (Type "Service" or "Product")');
type += ' Provider';
}
if(type == 'Service Provider'){
var region = prompt('Enter the state or country you wish to locate a vendor in (eg NSW, Australia)');
service = prompt("Enter the type of service you are looking for (eg cleaning, maintenance, carpet, glass)");
var gax = new GlideAjax('AL_checkUserGroup');
gax.addParam('sysparm_name','getScopes');
gax.addParam('sysparm_scope',service);
gax.getXML(reloadPage);
} else if(type == 'Product Provider'){
service = prompt("Enter the type of product you are looking for");
//prompts and glideAjax to develop url for PP
}
function reloadPage(response){
var list = response.responseXML.documentElement.getAttribute("answer");
//alert("Searching for a " + type + " in " + region + " who performs " + service + ". Found " + list + " results");
top.window.location.replace("https://instance.service-now.com/nav_to.do?uri=%2Fu_vendor_list_list.do%3Fsysparm_offset%3D%26sysparm_query%3Du_provider_type%253D" + type + "%255Eu_business_addressLIKE" + region + list + "%26sysparm_list_mode%3Dgrid");
}
callback(false);
}