Service Portal - \$sp.getRecordElements(.......) examples?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2017 10:01 AM
Hi everyone,
I am trying to use the $sp.getRecordElements(Object data, GlideRecord from, String names) method, but I am having very little success. I originally saw this used in another widget (the ServicePortal slushbucket widget); however, when I try to modify the code it fails.
To complicate the issue, the documentation on the developer.service-now.com conflicts with the ServicePortal Slush Bucket widgets usage of $sp.getRecordElements() . Example, service portal example has a return value from the method where the documentation states is a void.
Slush Bucket Widget - Server Script code :
(function () {
// grab names of available dependencies
data.all = [];
var gr = new GlideRecord('sp_dependency');
gr.orderBy('name');
gr.query();
while (gr.next()) {
var t = $sp.getRecordElements(gr, 'name,sys_id');
data.all.push(t);
}
})();
Developer.service-now.com Documentation :
getRecordElements(Object data, GlideRecord from, String names)
For the specified fields, copies the element's name, display value, and value into the data parameter.
Parameter(s):
Name | Type | Description |
---|---|---|
data | Object | The element's name, display value, and value for the specified fields are copied to this object. |
from | GlideRecord | The GlideRecord to process. |
names | String | A comma-separated list of field names. |
Type | Description |
---|---|
void | Method does not return a value |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2017 09:58 PM
did you modify the html template? it was referencing "item.name.display_value" which was the field name being passed from the serverscript, so if that changes, you need to change the html as well. before i did that, I was just getting blank rows. not sure if thats what you are running into as well but hope it helps.
https://community.servicenow.com/thread/280472
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2018 11:45 AM
Thanks for the tip! I missed the server switch name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-07-2018 07:04 AM
Hi Constantinekrick,
I tried the same in the scoped application and at first it was not working. Then I did some changes in the script code as below and it started working:
var t = {};
$sp.getRecordElements(t, gr, 'name,sys_id');
data.all.push(t);
As the documentation states, getRecordElements returns void, and it accepts three arguments. I created a variable and provided as the first argument and it is working now.