Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Is there a concise way to grab all columns and values from a table in widget server script?

davilu
Mega Sage

Is there a clear and concise way to grab every single column and value from a table, instead of manually pushing each item into an array?  For example, if I wanted to grab every column in HR Profile for a particular user, is there a more efficient and concise way to script that instead of the following:

data.profileArr = [];

var gr = new GlideRecord('sn_hr_core_profile');
gr.addQuery('sys_id', 'abcde');
gr.query();
if(gr.next()) {
  data.profileArr.push({
    dob: gr.getValue('date_of_birth'),
    place_of_birth: gr.getValue('place_of_birth'),
    ethnicity: gr.getValue('ethnicity'),
    gender: gr.getValue('gender'),
    etc,
    etc,
    etc
  })
}
1 REPLY 1

Vinayak Belgaon
Mega Guru

Hi Davilu,

 

There are several different functions  you can use from $sp api likgetFormgetRecordDisplayValuesgetRecordValues 

 

check below link for detail list

https://serviceportal.io/docs/documentation/widget_server_script_apis.md

https://developer.servicenow.com/dev.do#!/reference/api/rome/server/no-namespace/c_GlideSPScriptableScopedAPI#r_GSPS-getFields_GR_S

 

Regards

Vinayak