post by panv on Jul 1, 2021

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…

post by johnny on Jul 1, 2021

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;
});

post by panv on Jul 3, 2021

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 ?

post by panv on Jul 6, 2021

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.

post by johnny on Jul 6, 2021

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;

   $yourModel->doSomething($insertId);

    return $stateParameters;
});
1 / 5
Jul 2021