Filter result from catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 04:02 AM - edited 02-06-2023 07:01 AM
Hello,
When we went live with ServiceNow, our implementers created a Catalog Item for our Service Portal. When a position code is entered on the form, an applications field is populated from a Catalog Client Script which reaches back to a Script Include to get the position code data.
What I have been asked to do is to filter the applications field to not include a keyword when it is populated on the Service Portal form. Unfortunately, my Javascript is not quite up to speed on this. Can anyone share what the best approach would be here?
Thanks in advance,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 06:56 AM
It sounds like you are saying the applications variable is automatically populated when the position code variable is populated. Are you saying you don't want certain applications values to be automatically populated?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 06:57 AM
Hey Brad, that is correct. For example, we want all applications to populate in on the form except for those that begin with Active Directory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 06:35 AM
Post the contents of the Catalog Client Script and Script Include, and that will give me a better idea of what you're looking at.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 07:19 AM
Hey Brad, here you go. If you need any additional info, just let me know. Thanks again,
Script Include
var AccountRequestUtils = Class.create();
AccountRequestUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFunctions: function() {
// get all functionality associated with this position code
var functionalityArray = [];
var poscode = this.getParameter("sysparm_poscode");
var gr = new GlideRecord("u_role_functions");
gr.addQuery("u_position_number", poscode);
gr.query();
while (gr.next()) {
functionalityArray.push(gr.sys_id.toString());
}
return functionalityArray.toString();
},
type: 'AccountRequestUtils'
});
Catalog Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.clearValue(applications);
} else {
var ga = new GlideAjax("AccountRequestUtils");
ga.addParam("sysparm_name","getFunctions");
ga.addParam("sysparm_poscode", newValue);
ga.getXML(FunctionalityParse);
}
function FunctionalityParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue("applications",answer);
}
}