Run Event instead of opening sub-form

I have a form called GenerateReports. It is on my online account with Five. This form shows the Reports table, which currently has 1 record called Roster. There is a list-type subform for my join table, ReportGroups, which contains the group records which have been designed for the roster.

At run-time, when I click on a record in the sub-form (Report Groups), it properly shows the appropriate record and allows me to modify it if desired.

What I want to happen instead (for this form only) is to run a function whch causes a SQL statement to be executed to flip the join table’s IsSelected flag, then cancel the edit for the sub-form. So when clicked, all I want to see is the IsSelected field (which is included in the sub-form’s list) flipping from True to False and vice-versa.

My GenerateReports form has 2 pages, general and StudyGroups. In the second page, I put the function name, “FlipIsSelected” in the “On Selecting” event for the list page. I can’t get it to run the code. At this point, all the code has is alert(‘FlipIsSelected’); plus the exit statement.

I’m obviously doing something wrong, because I’m not getting the alert popping up. Can you explain what I did wrong? It is in my online database development copy if you want to look at it.

In the interest of efficiency, I will ask another related question:
When I do get the event to trigger properly and run the code, can you please advise me how to identify in the code the sub-form record I just clicked on, as that will be needed for the sql statement. Probably just the generated GUID key of that join table record. If I instead use actual table values, I would need the parent (Report) key and the child (Study Group) key to form the SQL statement. With just the join table’s GUID key, I think the SQL will work fine.


Ok, here is an update:

I was finally able to get the event to trigger. Instead of calling the function from the Study Groups page of the Generate Reports form, I put the call in the Do Create event of the Report Groups sub-form.

The function executed, but I got an error:
ReferenceError: alert is not defined > FlipIsSelected.fs.js:2:5

I’ve seen this before when trying to use the alert statement in my JavaScript, but this was when I was using my local Five installation. My research indicated that the alert command was not working in the local running version of Five, but would work on the cloud version, which opens the run-time in a new tab of my browser.

So would you please now ignore the first part of my post, and just answer the questions in the last paragraph?

Also, is there a reason alert won’t work? Thanks so much!

Hi Ron,

I have sent you an email, if you could please respond to that email, I will be able to log into your account and have a look for you.

Hi Jo-Anne,

Thanks for the help so far. Here is my function:

function FlipIsSelected(five, context, result)  {
    five.log("StudyGroupKey: " + context.Values.StudyGroupKey);
    five.log("ReportKey: " + context.Values.ReportKey);
    five.log("IsSelected: " + context.Values.IsSelected);
    five.log("ReportGroupsKey: " + context.Values.ReportGroupsKey);
    five.log("Action ID: " + five.actionID());
    let sql = "Update ReportGroups Set IsSelected = not(IsSelected) where ReportGroupsKey = ?";
    let queryResults = five.executeQuery(sql,0,context.Values.ReportGroupsKey, context.Values.StudyGroupKey);
    if (!queryResults.isOk()) {
        return "My Error: " + five.createError(queryResults);
     five.selectAction `GenerateReports`;
    return five.success(result);

I get this error:
TypeError: five.selectAction is not a function > FlipIsSelected.fs.js:13:24

So I guess I’m not formatting that properly. Pranoy gave the following in his answer in my question about programatically cancelling the edit and returning to the parent form:

I tried: five.selectAction(“GenerateReports”);
That didn’t work, and returned the same error.
I tried logging the actionID earlier in the code, and it didn’t show on the log.

I’m trying to make this function parameter driven, so I’d like to find a variable that represents the join table name (the table that the second page is tied to).

Also, I added a field to the table and form for ReportGroups. I have an IsSelected field, but I realize I also need an IsSelectedDefault field. The latter is maintained in the SetupReports context. The former is used in the GenerateReports context. I’m hoping to use SQL to update the IsSelectedDefault values into the IsSelected fields when I load the GenerateReport form. So I need to figure out in the ReportGroups form, how to make IsSelected field hidden if I’m coming from the SetupReports form, and IsSelectedDefault hidden if I’m coming from the GenerateReports form.

Not sure if I’m explaining correctly, but what variable is there to identify the form tied to the general page, when I’m defining the sub-form page, so I can make the proper field hidden? Thanks again!!!