getFields is not working in scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2017 04:01 AM
is there any substitute of getFields in scoped application as it is giving error. Please specify the use . Can getFields can be used in Script Include (Scoped App) .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2017 12:46 PM
GlideRecord also has a getElements method. This returns an array (if in scope) or an ArrayList (if in global) of all of the elements on the record. You can then loop through the array (in scope) or iterate through it (in global) to get things like the label, field name, and value.
var incident = new GlideRecord("incident");
incident.addActiveQuery();
incident.setLimit(1);
incident.query();
incident.next();
var elements = incident.getElements();
if (typeof elements.size != 'undefined') {
//we are in global scope, so iterate
for (var i=0; i<elements.size(); i++) {
var element = elements.get(i);
gs.info("Element label is {0}, name is {1}, value is {2}", element.getLabel(), element.getName(), incident.getValue(element.getName()));
}
} else {
//we are in scope, so loop over the array
for (var i=0; i<elements.length; i++) {
var element = elements[i];
gs.info("Element label is {0}, name is {1}, value is {2}", element.getLabel(), element.getName(), incident.getValue(element.getName()));
}
}
The above script should work in both global and scope.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2018 08:55 AM
That's a nice bit of code. Thanks for sharing that.
I find it particularly interesting that the returned object is different between global and scoped applications.
Anyone knows why it was done that way ?
I am just curious to know what would lead to that difference, if anyone knows.
Also, does anyone knows why getElements() and GlideScriptRecordUtil are not documented ?
Does it mean that we should not use those methods and classes, or is it simply that they are missing from the documentation ?
SN should certainly add that to their doc, given they already have getFields() and GlideRecordUtil.
Thanks.