- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2020 08:48 AM
Hi everyone,
A while back we implemented a custom reference field to the Group table on our Knowledge article templates and because we only had the one KB, the reference qualifier was simple. Now we're adding a second knowledge base and I need a dynamic reference qualifier that filters the available options based on the value of the kb_knowledge_base field.
The problem that I'm having is that all of the examples I've found for Dynamic and Advanced reference qualifiers is that they all use the same simple example, javascript:"company=" + current.company
Basically what I want to do is evaluate the kb_knowledge_base field, and if the value is KB1, I want to show Groups where type=X, and if the value is KB2, show Groups where type=y.
Should I use a dynamic filter for this, or a script include? Does anyone have any examples I might look at?
Thanks for any guidance.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2020 06:15 AM
You might be able to use current in this script include - try to decipher this
https://snprotips.com/blog/2019/12/18/can-script-includes-use-the-current-variable
Otherwise, change your reference qualifier to something like this
javascript:new u_KB_Utils().FilterKBApproverGroup(current.kb_knowledge_base);
then change the function declaration line in the script include and comment out the var kb line
FilterKBApproverGroup:function(kb) {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2020 09:40 AM
You can make a more complex query using "AND" / "OR" condition like:
javascript:'model_category='+current.variables.u_class_category_of_asset+'^install_status=6';
But in your case script include will be a better option.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2020 12:38 PM
Thanks for confirming that a script include is the way to go.
I'm having trouble getting mine to work, though. I've tried a couple different approaches, but so far I either get all groups, or no groups. If you wouldn't mind, could you take a look at my script and advise if there's a better way (or a glaring error)?
var u_KB_Utils = Class.create();
u_KB_Utils.prototype = {
initialize: function() {
},
FilterKBApproverGroup:function() {
var kb = current.kb_knowlege_base;
var gr = new GlideRecord('sys_user_group');
var answer = [];
//If KB is KB1, return KB1 groups
if (kb == '2393589edb2b405091d1c1911596193e'){
gr.addEncodedQuery('typeLIKE458de4f067671300dbfdbb2d07415ad6^active=true');
gr.query();
while(gr.next()){
answer.push(gr.group.toString());
}
return 'sys_idIN' + answer;
}
//If KB is KB2, return KB2 groups
else if (kb == 'bb0370019f22120047a2d126c42e7073'){
gr.addEncodedQuery('typeLIKEd879e93d1b255c1016a742e2cd4bcb0d^active=true');
gr.query();
while(gr.next()){
answer.push(gr.group.toString());
}
return 'sys_idIN' + answer;
}
},
type: 'u_KB_Utils'
};
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2020 11:23 PM
Try below code in your both loops and it will work.
var gp = ' ';
while (gr.next())
{
gp += (',' + gr.group);
}
return 'sys_idIN' + gp;
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2020 05:39 AM
Thanks, but unfortunately this doesn't seem to have changed anything, I get the same result. I took Brad's advice below and added some gs.info lines to my script and checked the log; one of them is saying the value of the kb variable is undefined, though I'm not sure why.