AvailableTimeRanges
Use the AvailableTimeRanges class to generate a list of time ranges for when a specific dimension scope is available. This method does not only inspect Availability records, but also existing Reservations that might block a dimension from being booked. It is useful for answering questions like: ‘When can this room be booked?’ or ‘Given these Staff members, who is available when?’. When used for Resources, you can include Services that must be available for the booking.
Methods
Inner Classes
Example for Lightning Flow
This code snippet shows how to make the method available for Lightning Flow:
public class TimeRangeSelector {
@InvocableMethod(label='Get available time range for single day' description='Returns a result object containing start and end time for the first available time range for the given Dimension Id' category='Scheduling')
public static List<TimeRangeResult> getTimeRangeForSingleDay(List<TimeRangeSelector.TimeRangeRequest> requests) {
List<TimeRangeResult> allResults = new List<TimeRangeResult>();
for (TimeRangeRequest request : requests) {
allResults.add(TimeRangeSelector.getResultForRequest(request));
}
return allResults;
}
private static TimeRangeResult getResultForRequest(TimeRangeRequest request) {
B25.AvailableTimeRanges.Context context = TimeRangeSelector.createContext(request);
B25.AvailableTimeRanges.Result result = B25.AvailableTimeRanges.getTimeRanges(context);
Map<Date, List<B25.AvailableTimeRanges.TimeRange>> timeRangesForDimension = result.timeRanges.get(request.dimensionId);
if (timeRangesForDimension != null) {
List<B25.AvailableTimeRanges.TimeRange> timeRanges = timeRangesForDimension.get(request.inputDate);
if (timeRanges != null && !timeRanges.isEmpty()) {
B25.AvailableTimeRanges.TimeRange timeRange = timeRanges[0];
TimeRangeResult timeRangeResult = new TimeRangeResult();
timeRangeResult.startTime = timeRange.startTime;
timeRangeResult.endTime = timeRange.endTime;
return timeRangeResult;
}
}
return null;
}
public class TimeRangeResult {
@InvocableVariable(Label='Start Time')
public Time startTime;
@InvocableVariable(Label='End Time')
public Time endTime;
}
public class TimeRangeRequest {
@InvocableVariable(Label='Dimension Name' Required=true)
public String dimensionName;
@InvocableVariable(Label='Dimension Field Name' Required=true)
public String dimensionFieldName;
@InvocableVariable(Label='Dimension Id' Required=true)
public Id dimensionId;
@InvocableVariable(Label='Date' Required=true)
public Date inputDate;
}
public static B25.AvailableTimeRanges.Context createContext(TimeRangeRequest timeRangeRequest) {
B25.AvailableTimeRanges.Context context = new B25.AvailableTimeRanges.Context();
context.dimensionName = timeRangeRequest.dimensionName;
context.dimensionFieldName = timeRangeRequest.dimensionFieldName;
context.dimensionIds = new Set<Id>{timeRangeRequest.dimensionId};
context.startDate = timeRangeRequest.inputDate;
context.endDate = timeRangeRequest.inputDate.addDays(1);
return context;
}
}
GoMeddo Rest API
In the GoMeddo Rest API, a similar function called Availability exists. It retrieves the opening times and reservations for a list of dimension Ids, enabling you to determine the still available locations and timeslots.
https://apidocs.gomeddo.com/#/availability/post_availability