- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
26m ago
Overview
In Workplace Visitor Management, hosts may create a visit that spans multiple calendar days without selecting Recurring invitation.
For example:
- From: 02.10.2026, 14:00
- To: 04.10.2026, 15:00
Although this looks like a three-day visit, it is stored as one continuous visit rather than as separate daily visit occurrences.
This can create operational issues at reception. If visitors are expected to check in and check out every day, the receptionist may only see the visit on the first day. On subsequent days, there may be no dedicated visit record available for check-in and check-out.
To address this, the Business Rule below automatically converts eligible multi-day visits into a daily recurring invitation.
Problem statement
Hosts do not always enable the Recurring invitation option when registering a visitor for several days.
Without a recurring pattern:
- The visitor registration is treated as a single continuous visit.
- Reception may only be able to process the visitor on the first day.
- Daily check-in and check-out cannot be handled consistently.
- Reception does not receive a separate visit registration for each day of the visitor’s stay.
For locations where visitors must leave the site and check out at the end of every day, this behavior is not suitable.
Solution
Create a before Insert / before Update Business Rule on the sn_wsd_visitor_visit table.
The rule evaluates the expected arrival and departure values:
- If the visit spans more than one calendar day, it automatically generates a daily recurring pattern.
- The daily occurrence uses the original arrival and departure times as its visit window.
- The recurrence includes every calendar day from the arrival date through the departure date.
- If the visit is changed back to a single-day visit, the recurring pattern is removed.
- A manually configured recurring pattern is not overwritten.
As a result, ServiceNow creates a dedicated visit occurrence for each day, allowing reception to process daily check-in and check-out.
Example
A host enters the following schedule:
Field Value
| From | 02.10.2026, 09:00 |
| To | 04.10.2026, 16:00 |
The Business Rule automatically creates a daily recurrence with:
- Repeat: Daily
- Number of days: 3
- Daily visit duration: 1 hour
- Occurrences:
- 02.10.2026, 09:00–16:00
- 03.10.2026, 09:00–16:00
- 04.10.2026, 09:00–16:00
This provides reception with one visit registration per day.
Business Rule configuration
Configure the Business Rule as follows:
Setting Value
| Name | Automatically create recurring multi-day visits |
| Table | sn_wsd_visitor_visit |
| When | Before |
| Insert | Selected |
| Update | Selected |
| Advanced | Selected |
| Order | 100 |
| Condition | (current.expected_arrival.changes() || current.expected_departure.changes()) && (!current.recurring_pattern.changes() || current.recurring_pattern == '') |
The condition ensures that the rule runs only when the arrival or departure date changes and avoids replacing a recurrence pattern that was explicitly configured by the user.
(function executeRule(current, previous /* null when async */) {
/**
* Converts a ServiceNow UTC date-time value in the format
* "YYYY-MM-DD HH:MM:SS" to a JavaScript Date object.
*
* @Param {String} dtStr ServiceNow date-time value in UTC.
* @returns {Date|null} Parsed Date object, or null if no value is provided.
*/
function parseSnowDate(dtStr) {
if (!dtStr) return null;
return new Date(dtStr.replace(' ', 'T') + 'Z');
}
var arrivalStr = current.getValue('expected_arrival');
var departureStr = current.getValue('expected_departure');
// A recurrence can only be created when both visit dates are available.
if (!arrivalStr || !departureStr) {
return;
}
// Create a daily recurrence only when the visit spans more than one calendar day.
if (arrivalStr.substring(0, 10) !== departureStr.substring(0, 10)) {
var arrivalDt = parseSnowDate(arrivalStr);
var departureDt = parseSnowDate(departureStr);
// Stop if either value cannot be parsed or the visit dates are not chronological.
if (!arrivalDt || !departureDt || departureDt <= arrivalDt) {
return;
}
/*
* Calculate the duration of each daily occurrence using only the
* time-of-day portions of the arrival and departure date-times.
*/
var arrTimeMs = (arrivalDt.getUTCHours() * 3600
+ arrivalDt.getUTCMinutes() * 60
+ arrivalDt.getUTCSeconds()) * 1000;
var depTimeMs = (departureDt.getUTCHours() * 3600
+ departureDt.getUTCMinutes() * 60
+ departureDt.getUTCSeconds()) * 1000;
var durationMs = depTimeMs - arrTimeMs;
// Daily occurrences must end later in the day than they begin.
if (durationMs <= 0) {
return;
}
// Calculate the total number of calendar days, including both start and end dates.
var arrDateOnly = Date.UTC(
arrivalDt.getUTCFullYear(), arrivalDt.getUTCMonth(), arrivalDt.getUTCDate()
);
var depDateOnly = Date.UTC(
departureDt.getUTCFullYear(), departureDt.getUTCMonth(), departureDt.getUTCDate()
);
var deltaDays = Math.round((depDateOnly - arrDateOnly) / 86400000) + 1;
/*
* The recurring_pattern field expects `options` to be a JSON string
* embedded within the outer recurring-pattern JSON object.
*/
var optionsInner = '{"count":' + deltaDays + ',"daysOfWeek":[]}';
// Build the daily recurrence definition expected by Workplace Visitor Management.
var pattern = {
duration: String(durationMs),
repeats: 'daily',
allDay: 'false',
endDate: departureStr,
options: optionsInner,
startDate: arrivalStr
};
// Save the generated recurrence pattern for the multi-day visit.
current.recurring_pattern.setValue(JSON.stringify(pattern));
} else {
// A single-day visit does not require a recurrence; remove any existing pattern.
current.recurring_pattern.setValue('');
}
})(current, previous);
Important limitation
This solution is intended only for locations where visitors are required to check out each evening and check in again on the following day.
It does not support a continuous multi-day visit where the visitor remains on site overnight.
For example, a visitor arriving on Monday at 09:00 and leaving on Wednesday at 16:00 will be converted into separate daily visits:
- Monday, 09:00–16:00
- Tuesday, 09:00–16:00
- Wednesday, 09:00–16:00
It will not represent a continuous on-site stay from Monday afternoon until Wednesday afternoon.
Before implementing this rule, confirm that daily check-out is required by your site’s visitor-management and security policies.
