Skip to main content

executeAction()

Last updated 3/02/2024

Example One

The following code executes an action on the Five server to send a leave request email to management.

Executing a mail merge action
function sendLeaveRequestEmail(five: Five, context: any, result: FiveError): FiveError {
const emailContext: any = {};
emailContext['SMTPToName'] = 'Bill Watts';
emailContext['SMTPToEmail'] = 'bill@gmail.com';
emailContext['SMTPSubject'] = 'Request for leave';

const executeResult = five.executeAction('LeaveRequest', emailContext);
if (executeResult.isOk() === false) {
return five.createError(executeResult, 'Failed to send email');
}
return five.success();
}

Example Two

The following code is identical to example one except we are initiating the action from the client. The optional onResult() will be executed when the action has completed on the server.

Executing a mail merge action initiated from the client
function sendLeaveRequestEmail(five: Five, context: any, result: FiveError): FiveError {
const emailContext: any = {};
emailContext['SMTPToName'] = 'Bill Watts';
emailContext['SMTPToEmail'] = 'bill@gmail.com';
emailContext['SMTPSubject'] = 'Request for leave';

const executeResult = five.executeAction('LeaveRequest', emailContext, () => {
five.showMessage('Mail has been sent');
});

if (executeResult.isOk() === false) {
return five.createError(executeResult, 'Failed to send email');
}
return five.success();
}

Example Three

The following code executes an action using the optional at paramater on the Five server to send a leave request email to management 24 hours later.

Executing a mail merge action at a future time
function sendLeaveRequestEmail(five: Five, context: any, result: FiveError): FiveError {
const emailContext: any = {};
emailContext['SMTPToName'] = 'Bill Watts';
emailContext['SMTPToEmail'] = 'bill@gmail.com';
emailContext['SMTPSubject'] = 'Request for leave';

const timeToSend = new Date();
timeToSend.setDate(timeToSend.getDate() + 1);

const executeResult = five.executeAction('LeaveRequest', emailContext, timeToSend);
if (executeResult.isOk() === false) {
return five.createError(executeResult, 'Failed to send email');
}
return five.success();
}