Skip to main content

executeFunction()

Last updated 6/06/2023

Example One

This code defines a function called RequestBook that takes in three parameters: five, context, and result. Within the function, a new object called variables is created. Two properties are added to this object: UserKey and Title. The values for these properties are taken from the five parameter's field property. The five parameter is then assigned to a new variable called _five. The five.executeFunction method is called with several parameters: the name of the function to execute RequestBookServer(), the variables object, and several empty strings. A callback function is also provided, which will be executed when the server response is received. If the server response has an errorCode of ErrErrorOk, the function returns without doing anything else. If the server response has a non-empty results property, the message is displayed using the _five.showMessage method. Finally, the function returns a success message using the five.success method.

RequestBook
function RequestBook(five: Five, context: any, result: FiveError) : FiveError {
const variables: any = {};
variables['UserKey'] = five.field.UserKey;
variables['Title'] = five.field.Title;

const _five = five;
five.executeFunction('RequestBookServer', variables, null, '', '', function (result) {
if (result.serverResponse.errorCode === 'ErrErrorOk') {
return;
}

const functionMessage: string = result.serverResponse.results;
if (functionMessage !== '') {
_five.showMessage(functionMessage);
}
});

return five.success(result);
}

Example Two

This code defines a function called CheckPrice that takes in three parameters: five, context, and result. Within the function, several variables are declared and initialized, including actionKey, functionKey, selectedFile, and functionName. The function then creates an object called variables and sets its properties to values from the five parameter. Next, the function calls the executeFunction method on the five object, passing in the functionName, variables, selectedFile, actionKey, and functionKey variables, as well as a callback function that will be executed when the function call is complete. If the result of the function call has an errorCode property equal to ErrErrorOk, the function returns without doing anything else. Otherwise, it displays a message using the showMessage method on the five object. Finally, the function returns the result parameter wrapped in a success object.

CheckPrice
function CheckPrice(five: Five, context: any, result: FiveError) : FiveError {
const actionKey: string = '';
const functionKey: string = '';
const selectedFile: File = null;
const functionName: string = 'CheckPriceServer';

const variables: any = {}
variables['StockKey'] = five.field.StockKey;
variables['TransactionDate'] = five.field.TransactionDate;
variables['Price'] = five.field.Price;

const _five: Five = five;
five.executeFunction(functionName, variables, selectedFile, actionKey, functionKey, function (result) {
if (result.serverResponse.errorCode === 'ErrErrorOk') {
return;
}

const functionMessage: string = result.serverResponse.results;
if (functionMessage !== '') {
_five.showMessage(functionMessage);
}
});

return five.success(result);
}