- 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:27 AM - edited 10-16-2023 02:32 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 02:33 AM
No, This is not working @Tai Vu .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 02:39 AM
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'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 02:42 AM
Thank You @Tai Vu
It is working now.