The CreatorCon Call for Content is officially open! Get started here.

Reference qualifier to display groups related author field in kb_knowledge table.

profile
Tera Contributor

On Knowledge form (kb_knowledge) create a field name ownership (should be a reference to user group table), it should show the list of group only of which “Author” is part of.

As soon as you save the form with “ownership group” an alert should appear with text “Owner of this knowledge article is “Author”.

 

We have used script include:

var UserGroupQuery = Class.create();
userGroupQuery.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroupsForUser: function(id) {
var groups = '';
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("user", id);
gr.query();
while (gr.next()) {
groups = groups + gr.group + ',';
}
return 'sys_idIN' + groups;
},

type: 'UserGroupQuery'
});

 

We have used Reference Qualifier:

javascript: new UserGroupQuery().getGroupsForUser(current.author)

 

This, is displaying all the groups instead of displaying only author presented group.

1 ACCEPTED SOLUTION

Hi @profile 

Is it worth your thumbs up? 😁

Can you mark my comment as solution so it might help the others with the same scenario.

 

Cheers,

Tai Vu

View solution in original post

7 REPLIES 7

Tai Vu
Kilo Patron
Kilo Patron

Hi @profile 

Your Script Include is created as a Client callable one Object.extendsObject(AbstractAjaxProcessor,...

Just copy the function and create new Script Include (Client Callable unchecked)

Also try the below adjusted script to avoid the redundant comma at the end.

 

getGroupsForUser: function(id) {
    var groups = [];
    var gr = new GlideRecord("sys_user_grmember");
    gr.addQuery("user", id);
    gr.query();
    while (gr.next()) {
        groups.push(gr.getValue('group'));
    }
    return 'sys_idIN' + groups.join(',');
}

 

 

Let me know if it works for you!

 

Cheers,

Tai Vu

profile
Tera Contributor

No, This is not working @Tai Vu .

Hey @profile 

I just updated my comment, you're calling a Client Callable Script Include in the Reference Qual.

The structure of the Script Include should look like this.

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

    getGroupsForUser: function(id) {
        var groups = [];
        var gr = new GlideRecord("sys_user_grmember");
        gr.addQuery("user", id);
        gr.query();
        while (gr.next()) {
            groups.push(gr.getValue('group'));
        }
        return 'sys_idIN' + groups.join(',');
    },

    type: 'UserGroupQuery'
};

 

profile
Tera Contributor

Thank You @Tai Vu 
It is working now.