How to create a Scheduled Job to refresh Neighborhoods ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 06:57 AM
Hi all,
Does anyone have the steps about how to create a Scheduled Job to refresh Neighborhoods?
I notice that if we create a new space that falls under a Nieghborhood criteria, that will NOT automatically associated with the Neighborhood. How can we automate this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2025 07:23 AM
Hello @fabio_milani
Please try below script in "Scheduled Jo ". Make it run as Administrator and select preferred schedule.
(function executeScheduleJob() {
var spaces = new GlideRecord('sn_wsd_core_space'); // Table where spaces are stored
spaces.addQuery('neighborhood', ''); // Get spaces that do not have a Neighborhood assigned
spaces.query();
while (spaces.next()) {
var neighborhood = getNeighborhoodForSpace(spaces); // Custom function to find the correct Neighborhood
if (neighborhood) {
spaces.neighborhood = neighborhood;
spaces.update();
}
}
function getNeighborhoodForSpace(space) {
var neighborhoods = new GlideRecord('sn_wsd_core_neighborhood'); // Neighborhood table
neighborhoods.query();
while (neighborhoods.next()) {
// Check if space meets the neighborhood criteria (example criteria: city, region, etc.)
if (space.city == neighborhoods.city && space.region == neighborhoods.region) {
return neighborhoods.sys_id;
}
}
return null;
}
})();
Kindly mark my answer as helpful and accept solution if it helped you in anyway,
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwN
eEISQCY