Save form data into 2 tables

st stikkimorey 17 Aug, 2018
Hi
​
I am trying to save data into 2 tables on submit. The first save data function saves an asset into tblAsset with auto increment field for the asset_id.
​
I want to add a record into another table using this new asset_id.
​
In the save action, after the save to tblAsset I have added a read function to read data back in from tblAsset with Model of Asset, order by created/asc Type, first matching record to try and get the latest asset to be added
​
After the read function I have another save action but this time to the second table and I have set Model name to Asset, data provider {data:Asset} write action:Insert, Data overide on insert:asset_id:{data:Asset.asset_id}
​
When I try to save in the second table however, the asset_id is not being saved. Is this because {data: #} only reads data on the form? If so how would I reference the data from my read function?
​
Or is there a better approach to use?
​
Thanks
Mikki
Gr GreyHead 17 Aug, 2018
Hi Mikki,
​
The new record id is added to the form data after the first Save Data action; you can access that in the second Save Data conditions box. Please add a Debugger action to the form On Submit event to see what the name of the record id is.
​
Bob
st stikkimorey 17 Aug, 2018
Thanks Bob
​
I've been looking for how to add a debugger action in Chronoconnectivity but I can't find it. Would I need to do that with a custom code function? If so, I would be grateful for a hint on how to get started.
​
Mikki
st stikkimorey 17 Aug, 2018
OK I've made a custom code function, entered {var:read_asset} and put it after the second read_data event on save and it is is returning:
​
{"Asset":{"dropcrate_id":"OhBot5","asset_id":"56"}} (shortened version of the array)
​
In my second Save Data function, I have the model name Asset, and the data provider as {var:read_asset}, the Write action as Insert
​
On save, the asset_id isnt being saved in the table, so I am trying to use Data override on Insert to force a value in. I cannot find the correct value to put in though.
​
asset_id:Asset.asset_id - just inserts Asset.asset_id
asset_id:{var:read_asset} - inserts the entire array
​
How can I get the asset_id out of the array?
​
Many thanks
​
Mikki
st stikkimorey 17 Aug, 2018
Hi
​
For anyone that has the same problem, the way to get to a value in a read_data function that is returning one result is:
​
{var:read_data#.Model.field}
​
Mikki
This topic is locked and no more replies can be posted.