- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2024 06:46 AM
Hello community! First time crying for help!
I am working on a service catalog item.
I am trying to use a script include and catalog client script (posted below, adapted from one I found here) and it's not working.
My use case is, the end user selects a user from a reference select box, that pre-populates the owner_asg select box only with groups that user is a member of.
The end user can change the user and the owner_asg box should change available groups to the new users groups.
I'm open to other solutions but thought the script include was the way to go. Any help is appreciated.
Catalog Client Script:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2024 02:03 PM
@Jason Thornton Here is the solution we finally concluded.
var GroupsMembership = Class.create();
GroupsMembership.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getGroups: function(record) {
gs.info('in script')
var groups = [];
var user = this.getParameter('sysparm_userID');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', record);
gr.addQuery('group.name','STARTSWITH','ASG');
gr.query();
while (gr.next()) {
groups.push(gr.group.sys_id);
gs.info(gr.group.sys_id)
}
gs.info("record is" + record);
return 'sys_idIN'+groups.toString();
},
type: 'GroupsMembership'
});
GroupsMembership.get = function() {
return new GroupsMembership();
};
Here is the reference qualifier.
//Variable Reference Qualifer Script
javascript: x_scopapp_utils.GroupsMembership.get().getGroups(current.variables.user);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2024 06:15 AM
Funny thing is "getUserByID" actually works in a scoped app, even though the docs say it does not. That could be new in Vancouver, not sure how far back it works.
And a scoped app is a scoped app whether it's meant for internal use only or for sale/distribution through the Store or not, so I'm not sure what you meant by that statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2024 09:57 AM
I don't know what SN instance you have, but in my PDI running
var x = gs.getUser().getUserByID('abel.tuter').getMyGroups();
in Scripts - Background in a private scope returns
Evaluator: com.glide.script.RhinoEcmaError: Cannot find function getUserByID in object com.glide.script.fencing.ScopedUser@12f41f9.
This in Vancouver patch2-hotfix1.
Sure
var x = gs.getUser().getMyGroups();
works, but here one needs
var x = gs.getUser().getUserByID('abel.tuter')...
which does not.
The method is only documented for global scope too.
Plus there are a ton of questions everywhere why it does not work in scopes and answers to those that it is not supported in scoped.
As for why it is important that an application is for Store or not is because if it is for Store one cannot use the global shimming technique - the solution would fail the review/assessment to authorize its distribution in Store.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2024 07:24 PM - edited ‎01-27-2024 07:50 PM
Weird, I get the same errors as you in both the Scripts - Background page and Xplore, BUT it does in fact work as a Reference Qualifier (Vancouver patch2-hotfix1-10-04-2023). I have the variable setup in the same scope as I'm trying in Scripts - Background and Xplore.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2024 05:23 AM
Perhaps because portal runs a lot of stuff in the background actually in global scope?