I hope you can help me with this question. In the past, I could call a client-side function and it would have access to fields, variables, stack items, etc. If this client-side function calls another function, the other function is always run on the server.
The server-side function did not have access to the variables that were defined client-side. It is unclear whether on the server side the function had access to five.field.whatever, or stack items. My go-to way to handle this was always define a context object in the client function, load it with whatever was needed, and send that context to the server function.
I believe since the last version of five came out, variables defined client-side are now available server-side. Can you verify this is true?
Can you also verify if five.field.whatever and five.stack.whatever is also automatically available on the server function?
The reason I ask, is that some forms need to call a client function to set variables, and some forms need to call a client function to initialize certain tables with the desired values. But I was never able to do both from the same form (say on the On Show event). So I would have to modify one function to also include things that were done in the other function (depending on which form is being used).
For example, my SaveActiveFormInfo function does this:
function SaveActiveFormInfo(five, context, result) {
// assign constant values based on current form
// assumes key field is named "{TableName}Key"
const myForm = five.actionID();
const myTable = five.getFive().getUserAction(five.getAction(myForm).key()).getForm().getDataSource().dataSourceId();
const keyField = myTable + "Key";
// see if the form is a setup form
const setupForms = JSON.parse(five.getVariable('SetupForms'));
const isSetupForm = setupForms.includes(myForm);
five.setVariable('MyForm', myForm);
five.setVariable('MyTable', myTable);
five.setVariable('MyKey', five.field[keyField]);
five.setVariable("IsSetupForm", isSetupForm);
return five.success(result);
}
My InitSelectedTables function does this:
const _five = five;
const userKey = five.getVariable('UserKey');
const myForm = five.actionID();
const myTable = five.getFive().getUserAction(five.getAction(myForm).key()).getForm().getDataSource().dataSourceId();
const keyField = "ReportsKey";
const isSetupForm = true;
five.setVariable('MyForm', myForm);
five.setVariable('MyTable', myTable);
five.setVariable('MyKey', five.field[keyField]);
five.setVariable("IsSetupForm", isSetupForm);
five.field.UserKey = userKey;
five.field.TableName = myTable;
// update groups
let selectedTable = 'SelectedGroups';
let myParms = {
UserKey: userKey,
SelectedTable: selectedTable,
SelectedEntityKey: 'StudyGroupKey',
SelectedEntityName: 'StudyGroupName',
LookupTable: 'StudyGroups',
LookupKeyField: 'StudyGroupsKey',
LookupNameField: 'GroupName',
JoinTable: 'ReportGroups',
JoinKeyField: 'ReportKey',
JoinKeyValue: five.field.ReportsKey,
JoinEntityField: 'StudyGroupKey'
};
five.executeFunction('InitSelectedTableServer', myParms, null, '', '', function (result) {
if (result.serverResponse.errorCode === 'ErrErrorOk') {
five.refreshTable(selectedTable);
five.reload();
return;
}
let functionMessage = result.serverResponse.results;
if (functionMessage !== '') {
_five.showMessage(functionMessage);
}
});
You may notice that the part that sets the variables near the top is a duplicate of what is in the SaveActiveFormInfo function. That part was put in this function because I didn’t think the server environment would know of those field names and variables. So I had to duplicate that logic.
The last 2 sections of this function (setting context object and calling server function) is actually repeated multiple times for different tables. So the server function may initialize selected Members, selected Reports, selected StudyGroups, etc.
So this is getting very complicated calling client-side functions which sometimes want to call other client-side functions just so they will have access to fields, stack, variables, etc.
I am doing it this way because I’m not knowledgeable about what can be done client-side and what can be done server side.
So, can you help me obtain this knowledge?
Can a client function call other client functions, or are any functions executed FROM a client function ALWAYS run in the context of the server?
Exactly what, in the current version of Five, is available in the server environment? I’m referring to variables, fields, stack items, etc.
I have the feeling that I’m making my application way too complex, with way too many moving parts, simply because I don’t know what is possible or known on the server side.
If I haven’t totally confused you, can you help me with this?
Thanks so much…








