How to import the database ID in a field in chronoforms v5?

How to display the auto-increment database ID in a ChronoForms v5 form field.

Overview

The issue occurs when trying to use custom PHP code to fetch the ID, which fails because the variable is undefined and the ID is not directly accessible that way.
Use the CF DB Save action, which automatically adds the new record ID to the form data array. Then, check the array with a Debugger action to locate and use the ID in your form.

Answered
ChronoForms v5
Ch Channelsupport 28 Dec, 2017
We use a registration form, made with Chronoforms v5. Applicants can enroll the form and we keep the results in our database. So far so good. Now, every form should have an unique number. Therefore we try to use the auto_increment field (ID) of the table from the database.
We don’t know how to import this ID in our form.

We use this php-code in a custom field of the form but no number appears:
<?php
// Get a db connection.
$db = JFactory::getDbo();

// Create a new query object.
$query = $db->getQuery(true);

$query->select('id');
$query->from($db->quoteName('aaa_datatable_SchoolAppFormXI'));
$query->where($db->quoteName('id')." = ".$db->quote($value));
$db->setQuery($query);
$result = $db->loadResult();
?>

Can someone give us advice about this?
Gr GreyHead 02 Jan, 2018
Answer
Hi Channelsupport ,

If you are using the CF DB Save action to save the data then the new record ID is added to the $form->data array by ChronoForms - add a Debugger action temporarily to the form On Submit action so see where it is saved.

Bob

PS In your custom code it looks as if $value is not defined anywhere.
Ch Channelsupport 02 Jan, 2018
Thanks for your reply.
We received similar information via a colleague.
The import of the ID-number in a field in chronoforms succeeded!

Channelsupport
This topic is locked and no more replies can be posted.