Forums

get the key from the table

ernst@volny.cz 06 Nov, 2022
good day.
I have a save to database action in chronoforms.
the action looks like this: (see picture)

in chronoforms6 I got the aid (key) of the newly added sentence like this:
$aid = $this->get('save_data3.aid');

but it doesn't work like that in chronoforms7. How do I do it here?

What I temporarily did was to read the last added sentence and get the aid from it. However, this is not a correct solution.
Colnem 11 Nov, 2022
Hi

For my side, I build a var {data:modified} ={data:Y-m-d H:i:s} before the Save Action, I save with modified = {data:modified} and I read data WHERE modified = {data:modified}. In this case it's better to use a SQL action to return only the aid field.

If there is possible you have two (or more) SQL inserts in the same second, you can use more conditions in the read action, like user = {user:id}…
ernst@volny.cz 13 Nov, 2022
yes, I understand all that and I agree. but the question is:
In chronoforms 6 I can use $this->get('save_data3.aid');

why doesn't it work in chronoforms 7 and is there any working alternative?

I don't need to do another database read, just get the key and pass it on
Colnem 14 Nov, 2022
Contact the developer
ernst@volny.cz 22 Nov, 2022
that's what I'm trying to do, but none of the developers are answering me
GreyHead 25 Nov, 2022
Hi Ernst,

I suggest that you turn on Debugging after the data save - that should show you the structure of the data to see where the id is.

Bob
ernst@volny.cz 28 Nov, 2022
I did that of course, but I don't see the id anywhere (unlike chronoforms 6).
gix.vax 08 Dec, 2022
for ID question: use uuid!!!

in all of my tables i use a field named uuid (char 36) that is populated by a trigger (only if null)
it's usefull to align different database records and in case, like this, you want to know the newly generated id without doubt.

In MYSQL (with phpmyadmin is very simple to do) add a trigger for every tablehave uuid
this is the code inside the trigger:
BEGIN
IF new.UUID IS NULL THEN
SET new.UUID = RIGHT(UUID(),36);
END IF;
END


with CF6/CC6 (i don't know in CF7)
in your forms put a filed named uuid that use shortcode {uuid:} for the value of your uuid field
If you use only a form to modify/insert records, use the syntax {var:my_read_data.model.uuid/(uuid:)} so new record have an uuid created by shortcode {uuid:}

Now, when you save you know the uuid value {data:uuid} that is an unique id
read record that have that {data:uuid} and you have your data for sure without doubt.

is safer than use data, cause if you have two user that write records, 1 second is not enough and milliseconds could not be too.
gix.vax 08 Dec, 2022
for your question, have you tryed
$rs=$this->get("my_red_data", "default")
You need to login to be able to post a reply.