Is there a concise way to grab all columns and values from a table in widget server script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 01:17 PM
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
})
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 09:55 PM
Hi Davilu,
There are several different functions you can use from $sp api like getForm, getRecordDisplayValues, getRecordValues
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