Get fields and their values from another table in SP widget?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2017 09:16 AM
I am working with the Ticket Fields widget in Service Portal. When I look at the code, I see
var fields = $sp.getFields(gr, 'fieldnameshere');
From what I can tell, this is simply getting specified field names from the current record. Then in the html body, we run a ng-repeat="field in data.fields" and print the label and value of each field. I like the layout of this widget and have cloned it. However, I have the current table set to the sysapproval_approver table. I would like the fields to be selected from the corresponding task that needs approval.
So basically, the server script sets gr to the current record. I set inc to the sysapproval record. From this point, I want to say fields = specific fields from the incident table, not the sysapproval table.
var gr = $sp.getRecord();
var inc= gr.sysapproval;
All help is much appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2017 06:12 PM
When using $sp.getRecord() with no parameters given the method will return the GlideRecord of the current "widget instance". To get a GlideRecord of a specific table then you must pass the parameters (table, sys_id) or (table, GlideElement).
So something like so should work:
var gr = $sp.getRecord('incident', '9c573169c611228700193229fff72400') // substitute table and sys_id with desired data
var inc_short_desc = gr.short_description; // substitute with the desired fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 03:37 AM
For some reason this didn't post as a question. However, I marked your response as helpful and liked it as it was exactly what I needed. Appreciate it!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 05:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 07:41 PM
No worries. Glad I could help.