Evaluator: java.lang.SecurityException: Method returned an object of type IdFunction which is not allowed in scope x_snc_app
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2015 09:53 AM
Hey guys,
I'm not sure if this is expected, but I could see it being a pain to deal with. I found that attempting string operations on the user_name field of the Users record generates this error when running in a non global context. You can reproduce this error by doing the following:
- Enable the security admin role by clicking the lock button next to the the Welcome System Administrator and check the box. Hit ok.
- Type Background in the navigator and click on Scripts - Background
- Select a non global scope and then paste this code in:
var ugr = new GlideRecord("sys_user");
ugr.query();
while (ugr.next()) {
gs.debug("Loading user " + ugr.user_name);
gs.debug("Loading user " + (ugr.user_name+'').toLowerCase() );
gs.debug("Loading user " + ugr.user_name.toLowerCase() );
}
4. Hit Run script.
The error:
x_snc_app: Loading user lucius.bagnoli (sys.scripts extended logging)
x_snc_app: Loading user lucius.bagnoli (sys.scripts extended logging)
Evaluator: java.lang.SecurityException: Method returned an object of type IdFunction which is not allowed in scope x_snc_app
Caused by error in script at line 6
3: while (ugr.next()) {
4: gs.debug("Loading user " + ugr.user_name);
5: gs.debug("Loading user " + (ugr.user_name+'').toLowerCase() );
==> 6: gs.debug("Loading user " + ugr.user_name.toLowerCase() );
7:
8: }
Evaluator: java.lang.SecurityException: Method returned an object of type IdFunction which is not allowed in scope x_snc_app
Caused by error in script at line -1
Background message, type:error, message: Method returned an object of type IdFunction which is not allowed in scope x_snc_app
Note that the error does not get triggered when casting the value to a string as in line 5.
What is the way around this, aside from making the cast? Is this expected behavior?
Thanks,
--- Travis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2015 10:00 AM
Travis,
I had a similar issue with a field I was doing a split() function on and had to change my script to current.field.toString().split(','). In your case you may want to try ugr.user_name.toString().toLowerCase().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2015 10:46 AM
Thanks guys. I'll go with the .toString(). I can't see a reason this lock down is a good idea. This seems to break the whole dot walk. These throw the same error:
gs.debug("Loading user " + ugr.last_name.toLowerCase() );
gs.debug("Loading user " + ugr.name.toLowerCase() );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2015 10:09 AM
It's because they drastically locked down GlideElement (the object you get from gliderecord.field) from scopes.
I've always made it a habit to use GlideRecord.getValue("field") instead of accessing the object property directly. It eliminates all the confusion of whether you have a real string object or not.
Besides, I've always had a person conflict with the thought of adding nothing to something in order to get a slightly different something.