- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2019 01:18 PM
I am making a copy of a global application into a scoped application. I've reached the ACLs.
This ACL seems to be returning the correct value but is not allowing the change to be saved and is throwing a log error.
ACL:
ACL Script:
answer = getAnswer();
gs.info("checkValidAssign Point 99 - answer - " + answer);
function getAnswer(){
var curUser = gs.getUserID();
var myUserObject = gs.getUser();
if(myUserObject.hasRole('Case - Take Ownership - All')){
return true;
}
// var func = new x_enig_commcase.CommercialCaseUtils();
var func = new global.caseManagementUtils();
var assign = func.getValidAssign();
gs.info("checkValidAssign Point 1 - assign - " + assign);
if(assign && !current.assigned_to.nil()){
gs.info("checkValidAssign - Point 2");
return true;
}
gs.info("checkValidAssign - Point 3.1 - current.sys_id = " + current.sys_id);
var assignGroup = current.assignment_group;
gs.info("checkValidAssign - Point 3.2 - assignGroup = " + assignGroup);
// if(myUserObject.isMemberOf(assignGroup)){
if(myUserObject.isMemberOf(current.assignment_group)){
gs.info("checkValidAssign - Point 4");
if(myUserObject.hasRole('Case - Take Ownership - My Groups')){
gs.info("checkValidAssign - Point 3");
return true;
}
}
return false;
}
Log entries:
I suspect the last log entry is pointing to the issue:
org.mozilla.javascript.EcmaError: Cannot read property "assigned_to" from null
Caused by error in Access Control: 'x_enig_commcase_ci_case.state' at line 14
11: }
12: // var func = new x_enig_commcase.CommercialCaseUtils();
13: var func = new global.caseManagementUtils();
==> 14: var assign = func.getValidAssign();
15:
16: gs.info("checkValidAssign Point 1 - assign - " + assign);
17:
The script include IS being called and seems to be returning the correct answer (I validated with log statements - Point 99 shows the final answer).
Script Include:
Function:
getValidAssign : function(){
//gs.info("getValidAssign - current.assigned_to = " + current.assigned_to);
if(getMyAssignments().toString().indexOf(current.assigned_to) > -1){
//gs.info("getValidAssign - into if");
return true;
}
return false;
},
I'm at a loss as to why the user can't change the state field. There are no other useful log entries. It looks like other ACLs that reference the "getValidAssign" function are also failing.
Can anyone tell me WHY this isn't working? Thank you!!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2019 05:35 PM
is function getMyAssignments() supposed to get all groups the user is a member of?
The OOTB code to do this doesn't work in scoped apps. Even if you call it in a global SI, you need to convert the JavaArray it returns into a JavaScript array. So, may as well just use this function instead. It is best to minimize dependencies to global code in scoped apps as much as possible.
You can use this function that replicates this code:
// original code credit to user Tim2222
// https://community.servicenow.com/community?id=community_question&sys_id=308eac4cdbcb5304b2102926ca9619fd&view_source=searchResult
function getMyGroups() {
var groups = [];
var grmember = new GlideRecord('sys_user_grmember');
grmember.addQuery('user', gs.getUserID());
grmember.addQuery('group.active', true);
grmember.query();
while(grmember.next()){
groups.push(grmember.getValue('group'));
}
// add all parent groups (this is global.getMyGroups behaviour)
var children = groups;
while(children.length > 0) {
var grp = new GlideAggregate('sys_user_group');
grp.addQuery('active', true);
grp.addQuery('sys_id', 'IN', children.join(','));
grp.addEncodedQuery('parentISNOTEMPTY');
grp.groupBy('parent');
grp.query();
children = [];
while(grp.next()) {
var parent_id = grp.getValue('parent');
if (groups.indexOf(parent_id) == -1) {
groups.push(parent_id);
children.push(parent_id);
}
}
}
return groups;
}
GlideUser().getMyGroups() | The Ultimate Scoped App Workaround Guide
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2019 01:32 PM
I see the script include is marked as client callable. However, the definition does not have
caseManagementUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor,{
and has a initialize function. Typically not seen in client callable Script includes.
Also try
if(current && getMyAssignments().toString().indexOf(current.assigned_to.toString()) > -1)
other option will be to send in current.assigned_to to funtion getValidAssign : function(assigned_to)
Vinod Kumar Kachineni
Community Rising Star 2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2019 01:35 PM
Oops!
That's correct! It's should not be a client callable one as well as you are calling from ACL.
It's better advised, to create a fresh SI as I suggested above. It will solve your issue definitely.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2019 06:25 PM
is a script somewhere calling GludeUser().getMyGroups()?
This function is not supported in scoped apps.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 12:13 AM
Hi,
The getMyGroups() has been fixed in the new Madrid Patch 6, so now it should work fine also in scoped applications,
Please refer to the PRB1347170 (https://docs.servicenow.com/bundle/madrid-release-notes/page/release-notes/quality/madrid-patch-6.ht...)
If I have answered your question, please mark my response as correct and/or helpful so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
Thank you
Cheers
Alberto