Copy a field to all other reservations on the form
This article explains how to copy values over to other reservations, when you have multi-select enabled on your calendar.
Prerequisites
Enable multi-select on your calendar: Set up Calendars & Views
Implement a form customizer class and make sure GoMeddo is configured to use it, as described in the first two sections of the Quick Start Guide
Make sure that the Account (B25__Account__c) and Title (B25__Title__c) fields are visible on the reservation form, as described in Add custom fields to the Reservation form
Event Handler
Implement the following event handler:
global class CopyField extends B25.FormEventHandler {
private SObjectField fieldToCopy;
global CopyField(SObjectField fieldToCopy) {
this.fieldToCopy = fieldToCopy;
}
global override void handleEvent(B25.FormEvent event, B25.Form form) {
B25.FormRecord activeRecord = form.getActiveRecord();
Object fieldValue = activeRecord.get(this.fieldToCopy);
if (form.hasParentRecord()) {
B25.FormRecord parentRecord = form.getParentRecord();
if (parentRecord != activeRecord) {
parentRecord.put(this.fieldToCopy, fieldValue);
}
}
if (form.hasChildRecords()) {
for (FormRecord childRecord : form.getChildRecords()) {
if (childRecord != activeRecord) {
childRecord.put(this.fieldToCopy, fieldValue);
}
}
}
}
}
The handler code above is slightly more complex than strictly necessary for this example, using form.hasParentRecord()
and form.hasChildRecords()
to prevent errors in case this code runs on a calendar without multi-select enabled.
Customizer Class
Now add the following lines to the customize method inside your customizer class:
form.getField(B25__Reservation__c.B25__Title__c).onUpdate(new CopyField(B25__Reservation__c.B25__Title__c));
form.getField(B25__Reservation__c.B25__Account__c).onUpdate(new CopyField(B25__Reservation__c.B25__Account__c));
This adds the handlers to the Account and Title fields, which will listen for updates to those fields, and then copy those values over to the other reservations.
Test your solution
Go to the calendar.
Use multi-select to create multiple reservations.
Give the reservation a title.
Switch to other reservations using the sidebar of the form.
Note that the titles all match.
Now set an Account on any reservation.
Switch to other reservations using the sidebar of the form.
Note that the accounts all match.
Full code
global with sharing class CustomFormLogic implements B25.Form.Customizer {
global void customize(B25.Form form) {
form.getField(B25__Reservation__c.B25__Title__c).onUpdate(new CopyField(B25__Reservation__c.B25__Title__c));
form.getField(B25__Reservation__c.B25__Account__c).onUpdate(new CopyField(B25__Reservation__c.B25__Account__c));
}
global class CopyField extends B25.FormEventHandler {
private SObjectField fieldToCopy;
global CopyField(SObjectField fieldToCopy) {
this.fieldToCopy = fieldToCopy;
}
global override void handleEvent(B25.FormEvent event, B25.Form form) {
B25.FormRecord activeRecord = form.getActiveRecord();
Object fieldValue = activeRecord.get(this.fieldToCopy);
if (form.hasParentRecord()) {
B25.FormRecord parentRecord = form.getParentRecord();
if (parentRecord != activeRecord) {
parentRecord.put(this.fieldToCopy, fieldValue);
}
}
if (form.hasChildRecords()) {
for (FormRecord childRecord : form.getChildRecords()) {
if (childRecord != activeRecord) {
childRecord.put(this.fieldToCopy, fieldValue);
}
}
}
}
}
}