
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2019 12:48 PM
Hi,
I have the below code that get data from the server and save it to data.events table
when I test that i got this error : Server JavaScript error Cannot set property "events" of undefined to ""
Do you have any idea?
(function($sp, input, data, options, gs) {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
if(!input){
data.events = [];
//spaceInfo.userId = userId; // haven't yet figured out if this is useful info
var userId = 'my name';
var gr = new GlideRecord('fm_m2m_user_to_space');
gr.addQuery("associated_user", userId);
gr.orderByDesc("primary_location");
gr.setLimit(1);
gr.query();
while (gr.next()) {
data.events.push({
'campusSysId': gr.facilities_space.building.campus.sys_id.toString(),
'externalBuildingId':gr.facilities_space.building.external_building_id.toString(),
'spaceInfo.externalLevelId': gr.facilities_space.floor.external_level_id.toString(),
'spaceInfo.externalSpaceId': gr.facilities_space.external_space_id.toString()
});
}
}
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2019 09:46 PM
You are missing the closure of your function
(function($sp, input, data, options, gs) {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
if(!input) {
data.events = [];
//spaceInfo.userId = userId; // haven't yet figured out if this is useful info
var userId = 'my name';
var gr = new GlideRecord('fm_m2m_user_to_space');
gr.addQuery("associated_user", userId);
gr.orderByDesc("primary_location");
gr.setLimit(1);
gr.query();
while (gr.next()) {
data.events.push({
'campusSysId': gr.facilities_space.building.campus.sys_id.toString(),
'externalBuildingId':gr.facilities_space.building.external_building_id.toString(),
'spaceInfo.externalLevelId': gr.facilities_space.floor.external_level_id.toString(),
'spaceInfo.externalSpaceId': gr.facilities_space.external_space_id.toString()
});
}
}
})($sp, input, data, options, gs) //Function closure here
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2019 09:38 PM
Hi,
First line is not required - (function($sp, input, data, options, gs) {.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2019 09:46 PM
You are missing the closure of your function
(function($sp, input, data, options, gs) {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
if(!input) {
data.events = [];
//spaceInfo.userId = userId; // haven't yet figured out if this is useful info
var userId = 'my name';
var gr = new GlideRecord('fm_m2m_user_to_space');
gr.addQuery("associated_user", userId);
gr.orderByDesc("primary_location");
gr.setLimit(1);
gr.query();
while (gr.next()) {
data.events.push({
'campusSysId': gr.facilities_space.building.campus.sys_id.toString(),
'externalBuildingId':gr.facilities_space.building.external_building_id.toString(),
'spaceInfo.externalLevelId': gr.facilities_space.floor.external_level_id.toString(),
'spaceInfo.externalSpaceId': gr.facilities_space.external_space_id.toString()
});
}
}
})($sp, input, data, options, gs) //Function closure here
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022