Utilizing the Office JavaScript API for an Outlook add-in, I encountered a issue with some code designed to save an appointment and close its window. Despite saving the appointment through the API, I continue to receive a "Discard changes" confirmation dialog box. This problem specifically arises when editing an existing appointment and adding custom properties before saving it.
Below is the crucial part of my TypeScript code:
private saveAppointmentAndSetProperty(appointment: any): Observable<any> {
const subject = new Subject<any>();
Office.context.mailbox.item.loadCustomPropertiesAsync(
result => {
if (this.isErrorResult(result)) {
subject.error(result.error.message);
} else {
const properties = result.value;
properties.set('MY_PROPERTY', true);
this.saveCustomProperties(properties, subject,
() => this.saveAppointment(appointment, subject));
}
}
);
return subject;
}
private saveCustomProperties(properties: any, subject: Subject<any>, callback: () => void): void {
properties.saveAsync(result => {
if (this.isErrorResult(result)) {
subject.error(result.error.message);
} else {
callback();
}
});
}
private saveAppointment(appointment: any, subject: Subject<any>): void {
appointment.saveAsync((asyncResult) => {
if (this.isErrorResult(asyncResult)) {
subject.error(asyncResult.error.message);
} else {
appointment.close();
subject.next(asyncResult.value);
subject.complete();
}
});
}
The function `saveAppointmentAndSetProperty()` serves as the entry point to the code. Interestingly, executing the same code within `saveAppointment()` does not exhibit any issues.