# Problem Returning to Form After Adding Record

**URL:** <https://www.five.org/t/problem-returning-to-form-after-adding-record/561>\
**Category:** How do I?\
**Created:** [July 7, 2025, 6:53pm UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561 "2025-07-07T18:53:07Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![RMittelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/rmittelman/32/447_2.png) [@RMittelman](https://www.five.org/u/RMittelman)\
**Post date:** [July 7, 2025, 6:53pm UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/1 "2025-07-07T18:53:07Z")

</div>

My StudyGroups form has a page for Members in the group, powered by a DataView. I can click the **AddMember** action button to add a new member to the list of members in the group. This runs the **AddGroupMember** function:

```auto
function AddGroupMember(five, context, result) {
        
        const parentForm = five.variable.MyForm; 
        const parentKey = five.variable.MyKey;
        
        let vars = {
            ParentTable: null,
            MemberKey: null,
            StudyGroupKey: null,
            IsLeader: false,
            IsCoordinator: false,
            IsCoLeader: false,
            IsAssistant: false,
            IsSunshine: false,
            GroupPaidDate: null,
            CheckNumber: null
        };

        if (parentForm === "Members") {
            vars.ParentTable = 'Members';
            vars.MemberKey = parentKey;
        } else if (parentForm === "StudyGroups") {
            vars.ParentTable = 'StudyGroups';
            vars.StudyGroupKey = parentKey;
        }
        five.setVariable("Vars", vars);
        // five.showMessage(JSON.stringify(five.variable.Vars));
        try {
            five.selectAction("AddGroupMemberProcess");
            return five.success(result);
        }
        catch (e) {
            five.showMessage("Error: " + e.message);
            return five.failure(result);
        }
    }

```

The **AddGroupMemberProcess** has screen fields for all of the fields in the **GroupMembers** table. It also has an action button to return directly back to the calling form, like a “cancel” button. This code is run:

```auto
function ReturnFromInputForm(five, context, result) {
    five.showMessage('MyForm: ' + five.variable.MyForm + '\nMyKey: ' + five.variable.MyKey);
    
    five.selectAction(five.variable.MyForm, five.variable.MyKey);
    // return five.success(result);
}

```

This code seems to run just fine, and return me to the StudyGroups form properly.

However, when I actually choose the field values in the process’ screen fields, then click the run checkmark, these functions are run:

```auto
function InsertGroupMember(five, context, result) {
    
    // make sure we selected member or group
    if (five.field.ParentTable === 'StudyGroups' && !five.field.MemberKey) {
        return five.createError("You must select a member before running this process.");
    }
    if (five.field.ParentTable === 'Members' && !five.field.StudyGroupKey) {
        return five.createError("You must select a study group before running this process.");
    }    
    
    let parms = {
            ParentTable: 'StudyGroupMembers',
            StudyGroupKey: five.field.StudyGroupKey ? `'${five.field.StudyGroupKey}'` : 'NULL',
            MemberKey: five.field.MemberKey ? `'${five.field.MemberKey}'` : 'NULL',
            IsLeader: five.field.isLeader ? 1 : 0,
            IsCoordinator: five.field.isCoordinator ? 1 : 0,
            IsCoLeader: five.field.isCoLeader ? 1 : 0,
            IsAssistant: five.field.isAssistant ? 1 : 0,
            IsSunshine: five.field.isSunshine ? 1 : 0,
            PaidDate: five.field.GroupPaidDate ? `'${five.field.GroupPaidDate}'` : 'NULL',
            CheckNumber: five.field.CheckNumber ? `'${five.field.CheckNumber}'` : 'NULL'
    }
    // five.log('Calling server function');
    five.executeFunction('InsertGroupMemberServer', parms, null, '', '', function (serverResult) {

        if (typeof serverResult.isOk === 'function' && serverResult.isOk()) {
            five.selectAction(five.variable.MyForm, five.variable.MyKey);
        } else {
            const rows = checkResult.rows; // rows is an array
            if (rows && rows.length > 0 && rows[0].ExistingCount > 0) {
                return five.createError("This member is already assigned to this study group.");
        }
        five.showMessage("Insert failed: " + errorMessage);
        }

    });
    // return five.success(result);
}

```

```auto
function InsertGroupMemberServer(five, context, result) {
    
    const newKey = five.uuid();
    const table = context.ParentTable;
    const groupKey = context.StudyGroupKey;
    const memberKey = context.MemberKey;
    const isLeader = context.IsLeader;
    const isCoordinator = context.IsCoordinator;
    const isCoLeader = context.IsCoLeader;
    const isAssistant = context.IsAssistant;
    const isSunshine = context.IsSunshine;
    const paidDate = context.PaidDate;
    const checkNumber = context.CheckNumber;
    
    // if member is already in group, warn and exit
    const checkSQL = `SELECT COUNT(*) AS ExistingCount FROM ${table} WHERE StudyGroupKey = ${groupKey} AND MemberKey = ${memberKey}`;
    const checkResult = five.executeQuery(checkSQL, 0);
    five.log(checkSQL);

    // If the query failed
    if (!checkResult.isOk || !checkResult.isOk()) {
        return five.createError("Could not check for existing member assignment.");
    }

    // If the record already exists
    const rows = checkResult.rows;
    if (rows && rows.length > 0 && rows[0].ExistingCount > 0) {
        return five.createError("This member is already assigned to this study group.");
    }
    const sql1 = `INSERT INTO ${table} ( StudyGroupMembersKey, StudyGroupKey, MemberKey, IsLeader, IsCoordinator, IsCoLeader, 
                    IsAssistant, IsSunshine, GroupPaidDate, CheckNumber ) `;
    const sql2 = `VALUES ( '${newKey}', ${groupKey}, ${memberKey}, ${isLeader}, ${isCoordinator}, ${isCoLeader}, ${isAssistant}, 
                    ${isSunshine}, ${paidDate}, ${checkNumber})`;
    let sql = sql1 + sql2;

    five.log(sql1);
    five.log(sql2);

    const queryResult = five.executeQuery(sql, 0);
    if (queryResult.isOk && queryResult.isOk()) {
        return five.success({ StudyGroupMembersKey: newKey });
    } else {
        let err = "Insert failed.";
        if (queryResult.errorMessage) {
            err = queryResult.errorMessage();
        } else if (queryResult.error) {
            err = queryResult.error;
        } else {
            err = JSON.stringify(queryResult); // fallback for inspection
        }
        five.log("Insert Error: " + err);
        return five.createError("Insert failed: " + err);
    }
}

```

Notice the code in the **InsertGroupMember** function that should return me to the original calling form if the insert went ok. This is basically the same code that gets executed when cancelling the process, but it does not return me to the calling form.

Can you please advise why this isn’t working as expected?

**UPDATE** :  
Since nothing visual happens on the process screen when clicking the checkmark, it looks like the new record has not been saved. So the user is tempted to click the checkmark again. This results in multiple member records being added to the study group. Similar to the issue happening when I edit a member in the group, I can click the **Return** button to go back to the calling form, but this shouldn’t need to be done. There must be a way to immediately get the process to complete and then execute code to return to the calling form. Again, we could really use an **After Complete** event.

---

<div class="post-metadata">

**Author:** ![RMittelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/rmittelman/32/447_2.png) [@RMittelman](https://www.five.org/u/RMittelman)\
**Post date:** [July 27, 2025, 6:17pm UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/2 "2025-07-27T18:17:12Z")

</div>

It’s been almost 3 weeks since I asked this question. I get that you folks are very busy, but the forum can’t help me if you don’t answer my questions. I’m stuck on this project without knowing these answers.

---

<div class="post-metadata">

**Author:** ![RMittelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/rmittelman/32/447_2.png) [@RMittelman](https://www.five.org/u/RMittelman)\
**Post date:** [August 13, 2025, 6:25pm UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/3 "2025-08-13T18:25:39Z")

</div>

Anything? Now it’s been 5 weeks.

---

<div class="post-metadata">

**Author:** ![Jo-Anne](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/jo-anne/32/45_2.png) [@Jo-Anne](https://www.five.org/u/Jo-Anne)\
**Post date:** [August 19, 2025, 1:48am UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/4 "2025-08-19T01:48:22Z")

</div>

Hi Ron,

The issues look like they are in your **InsertGroupMember** function.

Main issue

1.1 - The property **serverResult.isOk** , does not exist. Therefore, the **selectAction** functionality will never work.

This happened because the **InsertGroupMemberServer** function does not return the property **isOk** for the callback.

1.2 - The variable **errorMessage** and the property **checkResult** do not exist. Therefore, any validation of them would cause an error.

These issues can be found using the console in the browser.

Kind regards,

Jo

---

<div class="post-metadata">

**Author:** ![RMittelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/rmittelman/32/447_2.png) [@RMittelman](https://www.five.org/u/RMittelman)\
**Post date:** [October 7, 2025, 6:25pm UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/5 "2025-10-07T18:25:51Z")

</div>

Any progress in adding an AfterComplete event? As I mentioned, I can remove the function from the OnComplete event, and simply have users click the Return action button, but there should be a way to do this programatically without having to click that extra button. Thanks…

---

<div class="post-metadata">

**Author:** ![RMittelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/rmittelman/32/447_2.png) [@RMittelman](https://www.five.org/u/RMittelman)\
**Post date:** [October 7, 2025, 6:52pm UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/6 "2025-10-07T18:52:40Z")

</div>

Again, almost 2 months with no answer. This topic is directly related to the other topic, Delete and Edit Not working Properly. Have you made any progress on an **AfterUpdate** event? thanks…

---

<div class="post-metadata">

**Author:** ![eltonsantos](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@eltonsantos](https://www.five.org/u/eltonsantos)\
**Post date:** [October 10, 2025, 1:56am UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/7 "2025-10-10T01:56:39Z")

</div>

Hi Ron,

As mentioned previously by Jo, the property ‘ **isOk** ’ does not exist, as you can see on the image attached while debugging this function. Therefore, the **selectAction** will never be called (the menu won’t change).

**Solution based on the current code** : I believe you want to check for the property ’ **errorCode** ’ and compare it with the code ‘ **ErrErrorOk** ’ to indicate the process is OK.  
**Comment the line:**  
if (typeof serverResult.isOk === ‘function’ && serverResult.isOk()) {  
**Replace with the line:**  
if (serverResult.serverResponse.errorCode == ‘ErrErrorOk’) {

**Observation** : the function **InsertGroupMemberServer** is responsible for formatting the return for the callback. If you want to format a specific code or property, such as ‘ **isOk** ’, it needs to be changed there.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/five/original/2X/d/d817b8d00eb794e360931ed9db4e304eaf6ef32b.png)

Please let me know if you have any questions about my explanation.

Regards,  
Elton S

---

<div class="post-metadata">

**Author:** ![RMittelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/rmittelman/32/447_2.png) [@RMittelman](https://www.five.org/u/RMittelman)\
**Post date:** [October 11, 2025, 5:10pm UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/8 "2025-10-11T17:10:53Z")

</div>

Thanks Elton, that worked perfectly. I just changed the IF condition as you specified. I have no need to customize a specific response at this time.

Now that focus is returned to the calling form, is it possible to return to the specific page I was on? I can save the page name in a variable but how do I navigate to that page? Thanks…

---

<div class="post-metadata">

**Author:** ![eltonsantos](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@eltonsantos](https://www.five.org/u/eltonsantos)\
**Post date:** [October 13, 2025, 1:08am UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/9 "2025-10-13T01:08:17Z")

</div>

Hi Ron,

At this stage, we cannot return to a specific form page by using the selectAction function.

I will bring this feature request to our product review, and I will keep you updated about any outcome.

regards,  
Elton Santos

---

<div class="post-metadata">

**Author:** ![RMittelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/rmittelman/32/447_2.png) [@RMittelman](https://www.five.org/u/RMittelman)\
**Post date:** [October 13, 2025, 7:08pm UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/10 "2025-10-13T19:08:02Z")

</div>

Thanks Elton. That would be a nice feature to have, so when I return from adding/editing/deleting a detail record, it would go right back to the detail page I just came from. Please let me know if you folks do decide to do this.

---

<div class="post-metadata">

**Author:** ![RMittelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/rmittelman/32/447_2.png) [@RMittelman](https://www.five.org/u/RMittelman)\
**Post date:** [September 2, 2026, 10:02pm UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/11 "2026-09-02T22:02:12Z")

</div>

Now that I’m on version 3, I should be able to return to a prior form page according to the release notes and new documentation.

If I am in my **Members** form and click the **Groups** tab to go to that page, it runs my **SetSubformNameGroups** function. Since there is no way to know what the active page is on a given form, I needed to add a function for each page and each form.

```auto
function SetSubformNameGroups(five, context, result) {
    five.setVariable('SubformName', 'Groups');
    return five.success(result);
}

```

When I leave the page it runs this:

```auto
function SetSubformNameNone(five, context, result) {
    five.clearVariable('SubformName');
    return five.success(result);
}

```

When I go to another form, say to add a new group to a member, and click the Cancel or Return button, it runs this:

```auto
function ReturnToPriorForm(five, context, result) {
    
    const returnForm = five.getVariable('ReturnToForm') || five.getVariable('MyForm');
    const returnKey = five.getVariable('ReturnToKey') || five.getVariable('MyKey');
    const returnPage = five.getVariable('SubformName') || '';
    five.log(`returnForm=${returnForm}, returnKey=${returnKey}, returnPage=${returnPage}`);
    
    five.clearVariable('ReturnToForm');
    five.clearVariable('ReturnToKey');

    if (returnForm) {
        if (returnKey) {
            if (returnPage) {
                five.selectAction(returnForm, returnKey, returnPage);
            } else {
                five.selectAction(returnForm, returnKey);
            }
            
        } else {
            five.selectAction(returnForm);
        }  
    }

}

```

I just added the returnPage variable and extra if condition.

I expect it to return control to the Members form and also select the Groups page, but it doesn’t. It does properly go back to the form and selects the proper record, but doesn’t select the Groups page.

When I use the inspector, the SubformName variable is initially missing, then when I click to activate the **Groups** page, I see the variable there, but when I click back to the **General** page, the variable is still there, even though it should be removed.

Sometimes the inspector variables don’t refresh right away. For example, when I navigate to the Groups page, that variable doesn’t show up in the inspector. but if I switch to another inspector tab then back to Variables, it soes show. But moving back to the General page, the variable is still there in the inspector and the value is still “Groups”. So not only is the variable still there, when it is supposed to be there, the **selectAction** command is not taking me back to that page.

To further complicate matters, sometimes the inspector log is totally blank, even though i’ve told it to log things.

---

<div class="post-metadata">

**Author:** ![Jo-Anne](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/jo-anne/32/45_2.png) [@Jo-Anne](https://www.five.org/u/Jo-Anne)\
**Post date:** [September 3, 2026, 11:32pm UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/12 "2026-09-03T23:32:19Z")

</div>

Hi Ron,

I am unfamiliar with your application, could you please put together a small sample application of what is happening.

Our inspector is currently going through some testing, there will be improvements to it soon.

Kind regards,

Jo

---

<div class="post-metadata">

**Author:** ![RMittelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/rmittelman/32/447_2.png) [@RMittelman](https://www.five.org/u/RMittelman)\
**Post date:** [September 9, 2026, 12:02am UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/13 "2026-09-09T00:02:44Z")

</div>

It would be difficult to put this in a new application. So please look at my application, which I’ve copied to the **FDFs** folder on **OneDrive**. Elton has the shortcut and knows the IDs and passwords.

First:  
Does Five now have a way to easily identify the active page on a form? It never did before, so in the **Members** form, when I activate the **Groups** page, it runs a function called **SetsubformNameGroups** , which sets the variable **MyPage** to the ID of the page (it also sets **SubformName** , but that is being phased out).  
**Can you verify if there is a way to know the ID of the page without setting a variable?**

Second:  
If I open the **Members** form under **Setup** \> **Members and Groups** and select any member, then click the **Groups** page, that **MyPage** variable is now set to “Groups”.  
If I click the **Add Interest Group** button, it runs the **AddGroupMember** function. This function sets a context variable, then runs a process:

```auto
    five.setVariable('ReturnToForm', five.variable.MyForm);
    five.setVariable('ReturnToPage', five.variable.MyPage);
    
    try {
        five.selectAction("AddEditGroupMemberProcess");
        return five.success(result);
    }
    catch (e) {
        five.showMessage("Error: " + e.message);
        return five.failure(result);
    }

```

Note it sets **ReturnToForm** and **ReturnToPage** variables first.

If I get to that process, then click the **cancel** button, it runs this function:

```auto
function ReturnToPriorForm(five, context, result) {
    
    const returnForm = five.getVariable('ReturnToForm') || five.getVariable('MyForm');
    const returnKey = five.getVariable('ReturnToKey') || five.getVariable('MyKey');
    const returnPage = five.getVariable('ReturnToPage') || '';
    five.clearVariable('ReturnToForm');
    five.clearVariable('ReturnToKey');
    five.clearVariable('ReturnToPage');

    if (returnForm) {
        five.log(`ReturnToPriorForm: returnForm=${returnForm}, returnKey=${returnKey}, returnPage=${returnPage}`);
        if (returnKey) {
            five.selectAction(returnForm, returnKey, returnPage);
        } else {
            five.selectAction(returnForm);
        }  
    }

}

```

Note it sets local variables from known variables then uses them to return to the prior form and page. Note the log entry showing the proper values:

```auto
"ReturnToPriorForm: returnForm=Members, returnKey=728aad7f-bb02-4d51-922b-bf7be5a5b973, returnPage=Groups"

```

So the **selectAction** , given the proper arguments, should go to the **Groups** page according to your release notes. But instead, it goes to the proper form, selects the proper record, but stays on the **General** page.

Sorry to be so verbose, but I wanted to give you enough to see that it isn’t working for me.

I hope you can understand my explanation and advise why it’s not activating the Groups page.

Thanks…

---

<div class="post-metadata">

**Author:** ![Jo-Anne](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/jo-anne/32/45_2.png) [@Jo-Anne](https://www.five.org/u/Jo-Anne)\
**Post date:** [September 14, 2026, 1:51am UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/14 "2026-09-14T01:51:34Z")

</div>

Hi Ron,

This has been corrected; I will organize an upgrade for you soon once everything is ready.

Kind regards,

Jo

---

<div class="post-metadata">

**Author:** ![RMittelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/rmittelman/32/447_2.png) [@RMittelman](https://www.five.org/u/RMittelman)\
**Post date:** [September 14, 2026, 4:13am UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/15 "2026-09-14T04:13:29Z")

</div>

Thanks so much Jo. Please let me know when it is ready.

---

<div class="post-metadata">

**Author:** ![Jo-Anne](https://yyz2.discourse-cdn.com/flex030/user_avatar/www.five.org/jo-anne/32/45_2.png) [@Jo-Anne](https://www.five.org/u/Jo-Anne)\
**Post date:** [September 15, 2026, 1:35am UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/16 "2026-09-15T01:35:26Z")

</div>

Hi Ron,

Your account has been updated, and this should work correctly for you now.

Kind regards,

Jo

---

<div class="post-metadata">

**Author:** ![solidanchor201](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@solidanchor201](https://www.five.org/u/solidanchor201)\
**Post date:** [November 10, 2026, 6:27am UTC](https://www.five.org/t/problem-returning-to-form-after-adding-record/561/22 "2026-11-10T06:27:17Z")

</div>

This post was flagged by the community and is temporarily hidden.
