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.

Filter Catalog Item variable (Reference on Knowledge article) with Can Contribute ?

Guillaume D
Tera Contributor

Hi,

 

I have a catalog Item that return a list of Knowledge article from a particular Knowledge base in a Reference variable.

Current configuration :

Current configurationCurrent configuration

 

OOB, the list will show the articles the user can READ.

Instead, we want to only show the articles the user can Contribute (edit).

 

I changed the Reference qualifier to "Advanced" and tried a few thing without success.

  • I tried to call the "canWrite"' function from "KBKnowledge" script include directly into the qualifier.
  • I tried to encapsule the same "canWrite"' function in an client callable script include where I try do a glide record and return a list of KB sys_id.

Every time my list is empty. (But not sure I implemented previous solutions correctly)

 

Would you have some suggestion ?

 

Thank you !

1 ACCEPTED SOLUTION

Daniel Arnold
Kilo Sage

I haven't tried it myself but this is probably the approach you need to use in order to engage some more powerful server side logic in your reference qualifier by using a script include.

https://www.servicenow.com/community/developer-forum/need-a-canwrite-reference-qualifier/m-p/2116327

View solution in original post

2 REPLIES 2

Daniel Arnold
Kilo Sage

I haven't tried it myself but this is probably the approach you need to use in order to engage some more powerful server side logic in your reference qualifier by using a script include.

https://www.servicenow.com/community/developer-forum/need-a-canwrite-reference-qualifier/m-p/2116327

Hi Daniel,

 

Thank you for your suggestion.

I had try this approach without success, but with your link I was able to identify issue within my script include !

 

Short answer :

It works now, so I'll accept your message as solution !

 

Long answer :

The knowledge base I'm looking at contain more than 20k articles, so evaluating each article for canWrite permission is not efficient and not a viable solution for my need. (long loading time every time I'm looking at the list)
But for someone wanting to evaluate a smaller table it could totally work.

 

Here is the code I used, so other people can adjust it to their need.

Script include :

 

var myScriptInclude = Class.create();
myScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
        getCanWriteArticle: function() {
        var result = 'sys_idIN';
        var kb = new GlideRecord("kb_knowledge");
        kb.addEncodedQuery('kb_knowledge_base=************^language=en^workflow_state=published');
        kb.query();

        while (kb.next()) {
            if (kb.canWrite()) {
                result = result + kb.sys_id + ',';
            }
        }
        return result;
    },

    type: 'myScriptInclude'
});

 

 

Reference Qualifier :

 

javascript:new myScriptInclude().getCanWriteArticle()

 

 

EDIT : For reference qualifier : ":" -> ":"

GuillaumeD_0-1718365456300.png

I don't know with it's interpretated in the code sample