Just checking in to see if there was any progress.
To recap the situation, the following code in the GenerateReport client function works just fine, the report renders as expected when the GenerateReports form action button is clicked.
// run server function which will execute the query to load the stage table
const serverFunction = 'StageReportServer';
five.executeFunction('StageReportServer', parms, null, '', '', function (serverResult) {
// make sure serverResult was returned
if (!serverResult) {
_five.showMessage(`${serverFunction} returned no result.`);
return;
}
// handle error
if (serverResult.serverResponse.errorCode !== 'ErrErrorOk') {
const functionMessage = serverResult.serverResponse.message || 'Unknown server error';
_five.showMessage(functionMessage);
return;
}
// Now run the report (guaranteed staging completed)
const parms = { UserKey: userKey, RunKey: runKey }
five.log(`GenerateReport: parms=${JSON.stringify(parms)}`);
five.selectAction( reportID, parms );
});
As you can see, this code runs StageReportServer, which clears some records from the staging table StageGroupRoster, then loads it with the values from the report query. When this comes back, the callback function causes the report to run in the browser via the selectAction command.
On the other hand, the GenerateEmails form’s action button causes the GenerateEmails function to call the Generastrong textteEmailsServer function to run. this also loads the StageGroupRoster table, and this code gets executed:
// set variables and generate report
five.setVariable('RunKey', runKey);
five.setVariable('UserKey', userKey);
five.log(`Vars before report: UserKey=${five.getVariable('UserKey')}, RunKey=${five.getVariable('RunKey')}`);
const rr = five.executeAction(reportID, { UserKey: userKey, RunKey: runKey });
if (rr && rr.isOk && !rr.isOk()) {
return five.createError(`Report failed: ${reportID}`);
}
if (rr && rr.report) attachments.push(rr.report);
const ok = (rr && typeof rr.isOk === 'function') ? rr.isOk() : null;
five.log(`UserKey=${userKey}, RunKey=${runKey}, Report ${reportID}: ok=${ok}, keys=${Object.keys(rr||{}).join(',')}`);
const r = rr && rr.report ? String(rr.report) : '';
five.log(`UserKey=${userKey}, RunKey=${runKey}, report=${reportID}, report prefix=${r.substring(0, 40)}, len=${r.length}`);
The only real difference is that the executeAction with reportID is executed synchronously (I believe), then the result tested for length. The reportResult object is pushed into an array of attachments so they can be attached to the emails in a later step.
I made sure to set the UserKey and RunKey variables again, just before generating the report to make sure they were valid. I think we should just ignore the context object I send to the executeAction command, because you said they were only used if we had screen fields.
The only thing I can think of that may prevent the full report from being generated is that the RunKey is being lost somewhere between the time I set it and the time the report is rendered. This is needed because the StageGroupReport table is keyed by that.
It’s important to note that even before I was using RunKey, the report wouldn’t generate on the server. At that time, Jo said there was a problem with the UserKey variable being available since it was first saved from a client function. She said you folks did something to get this to work, but didn’t tell me what it was. This was many months ago. I think maybe we are having a similar issue with the RunKey variable, which is now needed to generate the report.
I’ve just uploaded a new FDF file if you need it.
If you need the steps again to try and generate the report and emails: Processing>GenerateEmails2>Select Generic email. Go to EmailInfo page> type in a single email address. Go to Reports page, select only Group Roster. Go to the Groups page, select first group. Click the Generate Report button.
Thanks for taking the time to read this. I can’t figure out why the report generates just fine in the browser but not on the server.