Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get fields and their values from another table in SP widget?

robhaas
Tera Contributor

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.

4 REPLIES 4

ChrisBurks
Giga Sage

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


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!


No worries. Glad I could help.