Thanks for the reply Riley.
Perhaps you can provide some clarification. Is calling a client-side function (via On Complete event) which then calls a server-side function after building context functionally the same as calling a server-side function via Do Complete event? It seems like the former would give more control.
Here is the server-side function called by Do Complete:
function ReSequenceReports(five, context, result) {
let sql = `SET @new_seq = 0; UPDATE Reports SET Seq = (@new_seq := @new_seq + 10) ORDER BY Seq;`;
let tableName = context.Transactions[0].Values.TableName;
result = five.executeQuery(sql, 0)
five.log('table: ' + tableName);
return five.success(result);
}
This is simple, but requires us to first have a field defined on the form for table name, and load that via On Show event using the logic from Jo.
Here is the prior method, using a client-side function called from On Complete:
function ReSequenceList(five, context, result) {
// get table name (THANKS JO!)
var myTable = five.getFive().getUserAction(five.getAction(five.actionID()).key()).getForm().getDataSource().dataSourceId();
// setup parameters
let myParms = {
Table: myTable
};
five.executeFunction('ReSequenceListServer', myParms, null, '', '', function (result) {
if (result.serverResponse.errorCode === 'ErrErrorOk') {
five.refreshTable(myTable);
five.reload();
return;
}
const functionMessage = result.serverResponse.results;
if (functionMessage !== '') {
five.showMessage(functionMessage);
}
});
return five.success(result);
}
And here is the server-side function:
function ReSequenceListServer(five, context, result) {
let myTable = context.Table;
five.log('ReSequenceListServer (' + myTable + ')');
let sql = `SET @new_seq = 0; UPDATE ${myTable} SET Seq = (@new_seq := @new_seq + 10) ORDER BY Seq;`;
five.log(sql);
result = five.executeQuery(sql, 0, context.UserKey)
return five.success(result);
}
This method uses more code, but doesn’t require adding a field to each form whose table may need to be re-sequenced.
Please advise pros and cons of using the 2 methods.
Here is fdf for sample app. Either way, we need Jo’s method to get the table name. The question is, do we use that method at form show time and require an extra form field, or use her method in a client-side function from On Complete.
testing-20241118-174600490047365.fdf (3.4 MB)
Thanks!!!
UPDATE: I modified the form events to use the client-side function which calls a server-side function, all caused by On Complete event. This did not work. Nothing got re-sequenced. When I removed the On Complete and re-added the simpler ReSequenceReports function to Do Complete, it works again. So we still need to figure out why the table name is in the Transactions array, but can’t be referred to directly in code without giving an error.