Hello,
I want to define a form to save the entered data to a table in the database. But when the user wants to edit the previous data he must be able to change this. I I added the following blocks:
- Read data block (on load, First matching record) with a behavior 'data merge'
- Save data block (on Submit) Data Source {data:} with behaviors 'Table Fields' and then the allowed fields.
When the user enters the form data a record is added but when the user changes the form data for a second time another record is added. This is not wat I want. The previous record must be updated or the last added record must be read during the load from the form. How can I configure this?
Best regards,
Ralph Gielkens.
you need to define the WHERE statement of your Read Data, it must read the previous user's record, do you have a table column for the user id ? you should have one
Same for "Save data", you need to have a WEHRE to update, so if you want to save a new record sometimes or update other times then you will need 2 Save Data actions in a switcher, the switcher will check if the Read Data returned a record or not
Your WHERE in both actions will look like this:
user_id = {user:id} // user_id is the table column where you store the user's id
and your Event Switcher "Value" will be {var:read_data_name.user_id}, replace "read_data_name" with the name of your read data action
Hello Max,
I'm trying to understand what you are saying but I can't get ik to work. How do I add 2 save actions in a switcher? I can't drag and drop actions to it. I only can add behaviors and event list to it. I added on load a read Data
and on Submit a save Data and an event switcher
What am I doing wrong?
Best regards,Ralph.
actually you do not need a switcher,use 2 Save Data actions, one for Insert and one for update, and control them using the "Run Conditions" behavior in each one, for the one to insert:
for the one to update you should make the Comparator "Is NOT Empty"
*Alternatively you could have another Read Data in the "submit" and place the Insert in "Record not found" of Read Data, and the Update in the "Record found" of Read data
Hi ralphg
The new v8.0.32 update has a new Save Data behavior called "Where Conditions", you can control if the conditions will run (update) or not (insert), that means you can have just one Save Data action, the condition will be just like my latest post image, but in the "Where Conditions" not "Run Conditions"