Lucky draw booking system
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 06:34 PM
I would like to create a booking form on ServiceNow. The only catch is that I would like it to have a lucky draw, or random draw function such that if a few people have selected the same time slot, the system will do a random allocation to one person.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 03:31 PM
Hi @Isaiah1
This is definitely possible, however what timeframe are you thinking because if I create a rule with no limits it would be between now and the end of time. 😂
Thanks
Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 01:44 AM
Hi Andrew it will be a monthly cut-off on the 10th
We have a monthly cut-off for bookings:
- All advance bookings must be made on or before the 10th of each month for the 2 slots available per day in the following month.
- If there are more advance bookings than boats available for a particular date, the allocation will be performed by a computerized random draw. Random draw will be done on the 10th of every month.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 07:45 AM - edited 02-22-2024 07:49 AM
Hi @jcmings
Obviously depending on whether this needs to be referenced against existing dates here’s an onload client script which should do the job.
//u_date - Populated field
function onLoad() {
var currentDate = new Date();
var currentDay = currentDate.getDate();
var currentMonth = currentDate.getMonth() + 1; // Adding 1 because months are zero-indexed
var currentYear = currentDate.getFullYear();
var nextMonth = currentMonth + 1;
var nextYear = currentYear;
if (nextMonth > 12) {
nextMonth = 1;
nextYear++;
}
var tenthDayNextMonth = new Date(nextYear, nextMonth - 1, 10); // Subtracting 1 because months are zero indexed
var randomDate;
if (currentDay > 11 || (currentDay === 11 && currentMonth === 12)) {
// If today's date is after the 11th of the month or on the 11th of December
// Generate a random date between now and the 10th of next month
randomDate = new Date(currentYear, currentMonth - 1, currentDay);
randomDate.setDate(randomDate.getDate() + Math.floor(Math.random() * (tenthDayNextMonth.getDate() - currentDay + 1)));
} else {
// If today's date is before the 11th of the month
// Generate a random date between now and the next 10th of the month
randomDate = new Date(currentYear, currentMonth - 1, currentDay);
randomDate.setDate(randomDate.getDate() + Math.floor(Math.random() * (10 - currentDay + 1)));
}
g_form.setValue('u_date', formatDate(randomDate));
}
function formatDate(date) {
var day = String(date.getDate()).padStart(2, '0');
var month = String(date.getMonth() + 1).padStart(2, '0'); // Adding 1 because months are zero indexed
var year = date.getFullYear();
return year + '-' + month + '-' + day; // Format: YYYY-MM-DD
}
Please mark as helpful or if its resolved the issue, CORRECT!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 07:48 PM
Thanks Andrew! Just to check does this code assign a random person to the slot of the day available? Or to a random date in the month? What I am looking for is there is one slot available (it's a club facility) but there are 10 who applied for the same slot on the same day. and only 1 person can get the slot of the day.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 09:07 PM
Hi @Andrew_TND just checking if I understood your solution correctly?