on_after_insert event not firing?

Questionson_after_insert event not firing?
Roy asked 9 years ago

I have used this method on a few pages now and it has been working for me. I now have a page where this method is not working.

the page uses a VendorNo in the var $vendnum which filters the data (e.g. VendorNo = ".$vendnum)

after inserting, I need to ensure the new record has the vendor ID that was used in the filter (eg. 100 )

However, the sql does not seem to be executing as the new records do not have the VendorNo set at all.

I don't see the difference in method or any errors between this page and the others that are working. Do you see any problems? How can I be sure the event is firing?

$e["on_after_insert"] = array("after_insert", null, true);

(the set_events($e) line of code was not allowed in the question form)

function after_insert($data)
$vendnum $_GET['vendorno']
$str = "update MemberVendorNos set VendorNo = ".$vendnum." where idMemberVendorNos = {$data["idMemberVendorNos"]};";




4 Answers
Abu Ghufran answered 9 years ago

If your first column of grid is "vendorno", you can get last insert id in after_insert event using following code.

$vendnum = $data["vendorno"];

After that you can use this var in sql.

If you search jqgrid_dist.php for "after_insert" you will see how it is passed.

// run insert sql …
$sql = "INSERT INTO {$this->table} $insert_str";

$insert_id = $this->execute_query($sql,"insert_id");

### P ###
// custom after insert event execution
if (!empty($this->events["on_after_insert"]))
$func = $this->events["on_after_insert"][0];
$obj = $this->events["on_after_insert"][1];
$continue = $this->events["on_after_insert"][2];

if ($obj)
call_user_func(array($obj,$func),array($pk_field => $insert_id, "params" => &$data));
call_user_func($func,array($pk_field => $insert_id, "params" => &$data));

if (!$continue)

Roy answered 9 years ago

Thanks for your reply.

The first column in the table is idMemberVendorNos and is the unique key for that table.

VenderNo is the value that links this row to a parent row in a one to many relation.

I need a way to set this value when inserting or after inserting a row into this table. This method has worked form in other cases, and I can't figure out why it is failing to update the row in this case.



Abu Ghufran answered 9 years ago

Hello Roy,

This event works as expected. If you can email code/sample-db then i can review it.
It's little difficult to suggest some solution.

For debugging, you can put echo statements in after_insert event callback and check the output in firebug's ajax response.
Hope it will help in analyzing the issue.

Roy answered 9 years ago

Thanks for your guidance. I have resolved this.


Your Answer

9 + 10 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.

How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?