- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 02:16 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 02:56 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 02:56 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 02:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 02:45 AM
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