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

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

Alka_Chaudhary
Mega Sage
Mega Sage

Hello @profile ,

To hold the group sys ids, an array needs to be created. And the script include should be client callable.

Please refer to the below script:-

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.push(gr.group.toString());
        }
		
        return 'sys_idIN' + groups;
    },
    type: 'UserGroupQuery'
});

To call the script include in reference qualifier use the below script:-

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

 Thank you.

Uday Soni05
Tera Guru

Hi @profile ,

Your script looks good even it should work but use array at the place of String

Update the code as below code

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;
},

 

And You also have to update your reference Qualifier Code I think you are also missing api name while calling the script include

Your Script

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

If your script is created in global scope write like this

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

(refer your api name in your script)

Update it accordingly your script scope

Let me know if you any further questions.

 

Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Uday