https://community.servicenow.com/thread/295109



Hi Experts,

 

I'm trying to retrieve all the fields in a form by using $sp.getForm in my widget server script, but it's returning an empty object array.  My code looks like this:

(function() {
var me = gs.getUserID();
data.user = gs.getUserDisplayName();
data.table ='x_dnf_questionnaire';
 
var gr = new GlideRecord('sys_ui_form');
gr.addQuery('name', data.table);
gr.query();
if(gr.next()) {
data.sys_id = gr.getValue('sys_id');
}
 
data.f = $sp.getForm(data.table, data.sys_id);
 
gs.addInfoMessage(data.f);

The above gs.addInfoMessage returns {}.  When I do a gs.addInfoMessage(data.f._sections), it actually returns all the different sections of my form in an object array as shown here:

https://community.servicenow.com/community/develop/blog/2017/02/07/portal-diaries-service-portal-approval-summarizer-in-portal.  Why is _fields not returning the fields of the form?

 

Thanks.