Thanks for a quick answer, Riley. Not sure I was able to implement it properly. Here is the query for my DataView:
SELECT
`StudyGroups`.`StudyGroupsKey` AS `StudyGroupsKey`,
`SelectedGroups`.`UserKey` AS `UserKey`,
`StudyGroups`.`GroupName` AS `GroupName`,
`UserKey` IS NOT NULL AS `IsSelected`
FROM
`StudyGroups`
LEFT JOIN `SelectedGroups` ON (
`StudyGroups`.`StudyGroupsKey` = `SelectedGroups`.`StudyGroupKey`
)
WHERE `UserKey` = ?
ORDER BY
`GroupName` ASC
Here is the parameter definition for the query:
Here is the code I’m using in the GenerateReportOnShow event:
function InitReportSubforms(five, context, result) {
// called from on_load event in SetupReports & GenerateReports
five.log('InitReportSubforms');
// context: { SelectTable: xxx, SelectField1: xxx, SelectVal1: guid, SelectField2: xxx, JoinTable: xxx,
// JoinField1: xxx, JoinVal1: guid, JoinField2: xxx, }
// setup common fields
const _five = five;
const selField1 = 'UserKey';
const selVal1 = five.currentUserKey();
const joinField1 = 'ReportKey';
const joinVal1 = five.field.ReportsKey;
// save userKey
five.setVariable("UserKey", selVal1);
// update study group fields
let selTable = 'SelectedGroups';
let selField2 = 'StudyGroupKey';
let joinTable = `ReportGroups`;
let joinField2 = 'StudyGroupKey';
five.executeFunction('InitSubformServer', { SelectTable: selTable, SelectField1: selField1, SelectVal1: selVal1,
SelectField2: selField2, JoinTable: joinTable, JoinField1: joinField1, JoinVal1: joinVal1, JoinField2: joinField2 },
null, '', '', function (result) {
if (result.serverResponse.errorCode === 'ErrErrorOk') {
five.refreshTable(joinTable);
five.reload();
return;
}
let functionMessage = result.serverResponse.results;
if (functionMessage !== '') {
_five.showMessage(functionMessage);
}
});
// update portfolio fields
selTable = 'SelectedPortfolios';
selField2 = 'PortfolioKey';
joinTable = `ReportPortfolios`;
joinField2 = 'PortfolioKey';
five.executeFunction('InitSubformServer', { SelectTable: selTable, SelectField1: selField1, SelectVal1: selVal1,
SelectField2: selField2, JoinTable: joinTable, JoinField1: joinField1, JoinVal1: joinVal1, JoinField2: joinField2 },
null, '', '', function (result) {
if (result.serverResponse.errorCode === 'ErrErrorOk') {
five.refreshTable(joinTable);
five.reload();
return;
}
let functionMessage = result.serverResponse.results;
if (functionMessage !== '') {
_five.showMessage(functionMessage);
}
});
return five.success(result);
}
Is there a scoping or lifetime for the variable “UserKey”? I’m setting it on showing the GenerateReports form.
Unfortunately, since I’m setting the variable at run-time, I can’t go back to the design-time tab of my browser, then open up the query definition, then tap the “run” button to see results of the query the same way I can with other queries, since it’s relying on a parameter that is not set at design-time.
So I don’t know if I’ve loaded the variable properly, or there is a scoping or lifetime issue with the variable. Any ideas? Thanks…