Unable to retrieve field names and labels from a sys_user record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 08:36 AM
Given a record (GlideRecordSecure), does anyone know what permissions are required to get the elements (GlideElement) and subsequently the descriptor (GlideElementDescriptor) from each element? Also, are you aware of any permissions or access to this data which may be more locked down for an on-prem ServiceNow instance?
The background is that a Client Script is used to call a Script Include function that ultimately returns an array of key-value pairs that are used to populate a dropdown on a form. Specifically, the function pulls a User record, retrieves the elements that make up the record, then examines each to extract only the ones that represent 'string' type columns on the sys_user table.
This has worked everywhere else, but in this one environment the value making it back to the browser is null ... presumably because an error is thrown though at this point I don't have confirmation of that due to lack of access to the environment. However, I was able to reproduce the behavior by intentionally throwing an error in the function in question. It feels like a permissions issue, but the user encountering it is an admin with full access to the sys_user table.
Here's a code snippet to show what is being done:
/**********************************************************************************************
* Returns a list of string fields from sys_user table
**********************************************************************************************/
MyClientCallableScript.getSysUserTableStringFields = function() {
var r = {
value: ''
};
var stringFieldInfo = [];
var user = new GlideRecordSecure('sys_user');
user.addActiveQuery();
user.setLimit(1);
user.query();
user.next()
var elements = user.getElements();
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
var descriptor = element.getED();
var result = descriptor.getInternalType();
if (result == 'string') {
var fieldInfo = {
name: element.getName(),
label: element.getLabel()
};
stringFieldInfo.push(fieldInfo);
}
}
r.value = JSON.stringify(stringFieldInfo);
return r;
};
Any input, even just suggestions, would be greatly appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 10:25 AM - edited 11-14-2023 10:29 AM
I guess the system is not going in to the for loop, it is not treating it as an array. instead of length replace it with size() as shown below.