- 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:29 PM
Hi,
Could you once try to call the script include in the ACL with the only name excluding global., that is, only by caseManagementUtils and check if it is working?
If that also doesn't work, please try to create the Script Include newly under Case Management Application, because I think the issue might be happening is because of the global.caseManagementUtils API name, although it is Accessible from All scope but due to the fact that the script include is in Custom Application scope where API name is supposed to start with x_case_management.caseManagementUtils, but unfortunately which is not.
While you create the SI newly, you could still keep it Accessible from All scopes and create it.
Hope this helps.
Mark helpful or correct based on impact.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2019 08:19 AM
I've put all the code into the ACL to validate if the problem is calling the script include or the 'getMyAssignments' function.
It's definitely 'getMyAssignments'. Here's the current code and I'm still getting the same errror:
answer = false;
var curUser = gs.getUserID();
var myUserObject = gs.getUser();
if(myUserObject.hasRole('Case - Take Ownership - All')){
answer = true;
}
gs.info("checkValidAssign Point 1");
if(getMyAssignments().toString().indexOf(current.assigned_to.toString()) > -1 && !current.assigned_to.nil()){
gs.info("checkValidAssign - Point 2");
answer = 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");
answer = true;
}
}
//return false;
gs.info("checkValidAssign - Point 99 - answer = " + answer);
Error Log:
org.mozilla.javascript.EcmaError: "getMyAssignments" is not defined.
Caused by error in Phase 2 Jelly: file:/glide/nodes/ecodevchild1xxxx/webapps/glide/itil/WEB-INF/ui.jtemplates/set_ref_can_write.xml.2 at line 1
==> 1: //answer = getAnswer();
2: answer = false;
3:
4: gs.info("checkValidAssign Point 99 - answer - " + answer);
Is 'getMyAssignments' valid in a scoped application?
Is it pulling a list of any open work assigned to the current user? (If I need to build it myself.)
Thanks!
By way of background, it may look like "Case Management" is a scoped application but it predates scoped apps and is most definitely in the global space. If I have to rebuild code, I'll do that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2019 08:50 AM
In Commercial Case application scope can you run the following lines as background script to check if the function is accessible. Please also look at Paul Morris's reply.
var myAssigned = getMyAssignments().toString();
gs.info("myAssigned = " + myAssigned);
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2019 09:35 AM
I ran that script in the background scope:
valuator: org.mozilla.javascript.EcmaError: "getMyAssignments" is not defined. Caused by error in script at line 1 ==> 1: var myAssigned = getMyAssignments().toString(); 2: gs.print("myAssigned = " + myAssigned);
I'm definitely not using 'GlideUser().getMyGroups()" here. (If it's somewhere else, I will know to deal with it.)
SHOULD 'getMyAssignments' be available in a scoped app? If so, perhaps I need a HI ticket.