Form Action Page from Data View Problems

Hello,

Glad to see you figured out how to access a form from a Data View.

Rather than using the previous action command, you could set a couple variables when the button on the Data View is pressed.

First, you could set a ‘GoBack’ variable to be true, then attach an action button to the form in which shows if this variable is true. Similarly, when this button is pressed, the ‘GoBack’ variable would then need to be set to false, therefore, the button will not show if you are not coming from the Data View. You would then also use five.selectAction within the code for this button in which you would select the actionID of the Data View.

In order to save the current member key, you can also set a variable that holds this value when the button on the Data View is pressed.

Regarding your third bold question, are these fields within the same form? If so, you may be able to make one a dependent field in which relies on the StudyGroupKey GUID Field.

Hope this helps,

Thanks,
Riley.

Thanks for the quick reply.

A couple of things I’m not sure I made clear.

I AM able to get from the data view to the GroupMembers form by clicking the group name, and executing selectAction supplying actionID() and five.field.StudyGroupMembersKey. so that part works.

When on the GroupMembers form, the group name is not one of the table fields that the form has access to, however it does have access to the StudyGroupKey GUID field. I’m trying to show GroupName on the form by defining a field called GroupName, without actually choosing it from the Field drop-down in design mode. I tried making it a _Lookup field with reference form = StudyGroups and dependent field = StudyGroupKey. It puts a drop-down in the form at run-time with choices available for the study group. What I EXPECTED was to just see the single study group name related to the StudyGroupKey, rather than a drop-down field. So the question is: Isn’t there a display type that just does the lookup without the user having to pick from a drop-down list? I also need this to show member name, looked up using MemberKey value from the StudyGroupMembers table. Is the solution having to add group and member names to the StudyGroupMembers table (at the cost of data normalization)?

Regarding your “go back” logic: Since I will be using this GroupMembers form only as a device to edit the values shown on the data view, why would I use an action button instead of using the on complete or do complete event? I’d still need that flag variable, and would still need to set it false when done.

Is there an issue using previousAction()? I’m curious why you suggested a work-around.

Also, you mentioned using select action with the data view as the actionID. I thought that using actionID() would give you the main form’s name, not the data view. Don’t I need to go back to the members form, and supply the saved actionID from that, along with the saved MembersKey? This question, if you answer it as expected, also helps answer why I would not use previousAction(), because that doesn’t let you specify a record to display.

UPDATE:

Even though I’m still curious about the questions in the prior message, I just realized when I use selectAction() and supply the form name and the StudyGroupMembersKey, the form appears but only that study group is showing in the list. Therefore, I don’t really need it on the form itself. The list is filtered down to the one study group I needed, AND the member that was active from the Members form.

However, when I use SelectAction to return to the members form, it seems like that list would also be filtered if I included the MembersKey. Is there a way to instead use previousAction? If I do, would it simply show the Members list until I select one? Is there a command for “go to record” once the Members form is loaded?

I’m having an issue trying to show certain forms. I believe it has to do with how I execute a function from another function.

Here is a function to set variable for the current member selected on the Members form:

function SaveActiveMember(five, context, result)  {
    five.setVariable("ActiveMember", five.field.MembersKey);
    return five.success(result);
}

I also need to show the map for the current customer. I can’t do both from on show event. I tried this:

    //five.setVariable("ActiveMember", five.field.MembersKey);
    five.executeFunction('SaveActiveMember', null, null, '', '', null);
    five.log('ActiveMember: ' + five.variable.ActiveMember);
...
rest of function
...

This did not work, but if I move the // from the first line to the second line, then it works. So obviously I didn’t use proper syntax on the executeFunction.

Can you please help me with that? It would be more readable if I could have a ShowCustomer function called from on show, and that function could call SaveActiveCustomer and ShowMap functions, right?

Also, regarding your earlier “go back” suggestion, what is the syntax for checking to see if a variable exists? Do I simply say "if(five.variable.GoBack === true)…?

Since I’m only executing this form from a button click either from the Members form or the StudyGroups form, do I even need that variable? I need an ActiveForm variable which I set from the actionID, then check that variable when the on Complete is triggered from the MemberGroups form? But what event is triggered if I instead cancel the MemberGroups form? I would still want to go back to the calling form. Is there a “on close” event?

Hello,

One solution would be to set a variable containing the StudyGroupKey and then setting the default value of the look up to be this variable. Alternatively, you could add group and member names to the table as well.

For the ‘Go Back’ button, you could use it on ‘OnComplete’ or ‘DoComplete’, but there is really no way of telling the user that it takes them back. With an action button, you can specify ‘Go Back’ as text on the button. Regarding the Data View actionID, I was saying you could use this on the ‘Go Back’ button in order to take the user back to the Data View.

Thanks,
Riley.

Hello,

I am unsure why you are wanting to use a seperate function to set a variable, but to make it work, you will need to parse the variables to the executeFunction call.

Within the function that calls SaveActiveMember, you will need to create an array to store variables:

const variables = {};
variables["ActiveMember"] = five.field.MembersKey;
five.executeFunction("SaveActiveMember", variables, null, null, null, function (result) {});

Then, within the SaveActiveMember function, you will be able to acquire the values within the variables array from the context:

const activeMember = context.ActiveMember;
five.setVariable("ActiveMember", activeMember);

Also, regarding the ‘Go Back’ button, within the show if, you would just write:
=five.variable.GoBack

(i.e. if this variable is true, the button will show, otherwise, it will not show)

Hope this helps,

Thanks,
Riley.

Now you’re confusing me. Maybe I didn’t state the question correctly.

If I set on show event to run the SaveActiveMember function, it needs no variables, it just runs client side and sets the variables based on five.field.Memberkey. why would I need to fill context if I’m calling the same function that works from an event? I’m just trying to find out how to call it from another function.

As far as why, sometimes we need multiple things done from the same event. In this case, save active member and setup the map when the on show event fires. It seems more maintainable to have a ShowMember function that calls the other functions.

Regarding the go back button, that worries me. The user may click that before saving the changed record. Or the user may click the Back button without changing anything. Best case: ANYTHING the user does on this form to either save, cancel or go back should trigger a function to return to the previous form. I see an on complete and an on cancel event, but is there an event that fires when you click the back button?

I Don’t feel it’s necessary to advise the user he/she is “going back”. If the only purpose of this GroupMembers form is to edit a record in the StudyGroupMembers table, the user doesn’t need to know that.

Testing this, I added an action button and put a function name in the On Complete of the action button. Starting with previousAction(), this is unacceptable because it loads the Members list but doesn’t return to the member previously selected. Changing the function to use selectAction(‘Members’, five.variable.ActiveMember) works, as it returns me to the Members form with the same member active. Perfect!

Now, I need to differentiate between save, cancel or go back actions. Clicking the “go back” button gets me back, but how do I save any changes to the record in the function code? I can have 2 buttons, “Cancel” and “Return”. Cancel will just go back, while Return will save the record if needed THEN go back. I presume if there are no changes and the function code says to save, this will not hurt anything, right? So maybe I don’t need to know if there is a pending change. Please advise how to save the record in the function code. Finally, How can I disable the default Save button and the X button and the Return button?

Thanks so much…

Ron Mittelman

Sorry for all the questions. I’ve been able to combine these functions with some success.

My ShowMap function used to work, but now it doesn’t when I call it from another function. Please confirm my belief that if I execute a function, it is executed on the server-side. Assuming this is correct, the ShowMap function refers to a document object (see existing ShowMap statement):

mapImage = document.getElementById('google-map');

Is it possible to send a document inside a context object? This would be necessary if I wanted to refer to it in a server-side function, right?
I could add a parameter to the context object, such as:

Document: document

Then in the ShowMap function, I could say:

var document = context.Document;

Would that work?

I still need to figure out the answers to the bold questions above. Thanks…

Hello,

Regarding your first message:

  • It sounds like you may be better off just using the save button as a way to go back to the previous page instead of introducing multiple action buttons.

However, I will still answer the bold questions.

How do I save any changes to the record in the function code?
In order to save changes to a record within function code, you are able to gather all fields from the form and then use an UPDATE sql statement where you update the record in which was being edited.

How can I disable the default Save button and the X button and the Return button?
Unfortunately, you cannot disable these buttons, however, you can change the way they appear (i.e. set them to some custom text). Given this, you could potentially change the save button to ‘Go Back’ or ‘Return’, and this way, the record will also save as normal without having to do any additional SQL.

Here is some documentation regarding changing the display of various default buttons.

Regarding your second message
Yes, it is possible to send a document object from the front end to the back end, however, form the code snippet you provided, it seems you are sending the whole document object rather than just the mapImage object.

Hope this helps,

Thanks,
Riley.

If you look at the ShowMap code, you will see it uses the document object more than once. That’s why I chose to send the document to the called function. My plan was to have a client-side function that was called from on show for both members form and StudyGroups form. The members form is more complicated, because it has to show the map also.

Is it true that when you execute a function from code, it is then run on server-side? If so, that is why i was getting an error when referring to the document object. That is why I wanted to send the document object along in the context. But it didn’t seem to work. It seems you can’t send an object, only a value. But I may be wrong about that, as I’m fairly new to web development.

I’ve decided to just keep things as simple as possible for now. So the ShowMap function will remain client-side, and it works now. I added some code lines to set the variables.

    // first save member info
    five.setVariable('ActiveForm', five.actionID());
    five.setVariable('ActiveTable', five.actionID());
    five.setVariable('ActiveKey', five.field.MembersKey);

I’ve simplified the variables. Since my forms are named the same as my tables, I just use actionID(). ActiveKey variable will either be the MembersKey or the StudyGroupsKey, depending on which of the 2 forms I’m coming from. I’ll set the same 3 variables from on show of StudyGroups form.

Since I run the ShowMap function multiple times from the Members form, I’m thinking of surrounding the above 3 lines with

if(five.variable.ActiveForm !== five.actionID())

Therefore the first 3 lines won’t keep executing in case I run ShowMap again for the same form. Please verify this will not cause an error, especially the first time, when the ActiveForm variable will be undefined.

As far as saving the record changes on the GroupMembers form, I will just use the normal checkmark button. Then the custom Return button will just go back to the same form and record.

Hello,

Happy to see you figured it out!

Also it is true then when using five.executeFunction, the function runs on the server side. Regarding your second bold statement, I cannot see why any errors would occur, however, to be extra safe, you could also encase this in a further if statement to check if the variable actually exists.

Thanks,
RIley.

Since your documentation is not complete, would you please share what the if statement would be? The syntax for testing whether a variable exists or not?

Thanks…

Ron Mittelman

Hello,

You go,

if (five.variable.NAME !== null) {
…Your code here…
}

Thanks,
Riley.