Is there a way to use the newly inserted value of id in another field?

let’s suppose the newly inserted field will have an ID of 1101.
Is there a way to use this value in another field ? for example :

$crud->callbackBeforeInsert (
  function ($cbData) {
    $cbData->data['desc'] = 'description_' . $cbData->data['id'];
    return $cbData;

I want to get the field description : description_1101

By the way, this does not work…

Hello @panv ,

I think you are looking for the callbackAfterInsert that you can get the insertId like this:

$crud->callbackAfterInsert(function ($stateParameters) {
   $insertId = $stateParameters->insertId;

    return $stateParameters;

Hello @johnny

I tried using it as below :

$crud->callbackAfterInsert (
  function ($sp) {
    $iID = $sp->insertId;
    $sp->data['order_desc'] = 'test';
    //$iID . $sp->data['order_docs']; // commented out to see if I use a static value as 'test'
    return $sp;

Unfortunately, nothing happens to the filed ‘order_docs’ …
please note that I am using GC Community.

What am I missing here ?

I think I cannot modify the data the way I tried on my previous reply. I should use the `insertId’ to write my own script that will modify the database. Is that true @johnny ??
Thank you.

Hello @panv,

If I understood your question correctly, yes when we use the after callbacks (e.g. callbackAfterInsert ) then if we would like to have something custom to the database you should do it manually for example:

   $insertId = $stateParameters->insertId;


    return $stateParameters;
1 Like