Need to show only active knowledge bases and canconrtibute knowledge bases in the field

prasannasun
Tera Contributor

Hi ,

 

I have requirement as per that I have created a custom field called "u_knowledge_base" in the kb_submission table which is in open submission module. here in the field I have to show only the knowledge bases which are active and the users who can have access to can contribute.

 

Bt for me it is showing all the articles who have read and conrtibute access. But for me I have to show the knowledge bases who have canconrtibute access.

 

is ther any possibility can help me please this is high priority.

 

6 REPLIES 6

Bhavya11
Kilo Patron
Kilo Patron

Hi @prasannasun ,

 

you can try with this using advanced reference qualifier by using script include.

do the following 

1. Create one script include

 

Script include :

Name: KBUserCriteriaUtils

var KBUserCriteriaUtils = Class.create();
KBUserCriteriaUtils.prototype = {
    initialize: function() {
    },

    getContributableKnowledgeBases: function() {
        var userSysId = gs.getUserID();
        var kbSysIds = [];

        var grUserCriteria = new GlideRecord('kb_uc_can_contribute_mtom');
        grUserCriteria.addQuery('user_criteria.active', true);
        grUserCriteria.query();

        while (grUserCriteria.next()) {
            var ucSysId = grUserCriteria.getValue('user_criteria');
            var uc = new GlideUserCriteria();
            if (uc.evaluate(ucSysId, userSysId)) {
                // Now find all knowledge bases associated with this user criteria.
                var grKB = new GlideRecord('kb_knowledge_base');
                grKB.addActiveQuery();
                grKB.addQuery('can_contribute_user_criteria', ucSysId);
                grKB.query();
                while (grKB.next()) {
                    kbSysIds.push(grKB.getUniqueValue());
                }
            }
        }
        
        // Also include KBs with no user criteria for 'can_contribute' (public).
        var grPublicKB = new GlideRecord('kb_knowledge_base');
        grPublicKB.addActiveQuery();
        grPublicKB.addNullQuery('can_contribute_user_criteria');
        grPublicKB.query();
        while (grPublicKB.next()) {
            kbSysIds.push(grPublicKB.getUniqueValue());
        }

        var uniqueKBIds = new ArrayUtil().unique(kbSysIds);
        return 'sys_idIN' + uniqueKBIds.join(',');
    },

    type: 'KBUserCriteriaUtils'
};

 

2. Open the field called 'u_knowledge_base', add reference qualifier like below

Bhavya11_0-1758697587107.png

 

javascript:new KBUserCriteriaUtils().getContributableKnowledgeBases();

 

then try to test the logic. it will filter the Knowledge Base, where user can contribute and also public Knowledge Base  

Bhavya11_1-1758697648331.png

 

If this information proves useful, kindly mark it as helpful or accepted solution.

 

Thanks,

BK

 

Hi Bhavya, 

Thak you for your response not sure what is wrong I tried your script logic but still showing all the knowledge bases for the users

Hi Bhavya,

 

Is it okay Can I share my instance details I am not sure if something is wrong. I am not able to fix that and this is the high priority issue. Would you able to help me

hi @prasannasun ,

 

can you just brief about the configuration you have done .

Please test with proper role user. if you test as an admin all most all user criteria will pass so it will start showing all Knowledge Base

 

 

Thanks,

BK