Perform some task after adding new record.

QuestionsPerform some task after adding new record.
Michael asked 11 years ago

Hi,

Is it possible to automatically perform a task after a user has added a new record?

For example, once a user as added a new record to the database, I would like to e-mail a copy of what was added to an e-mail address.

Is this possible??

Thanks,

Michael

5 Answers
Abu Ghufran answered 11 years ago

Hello,

You can put your email code in on_after_insert and it will be called after insert.

$e["on_after_insert"] = array("my_after_insert", null, true);
$grid->set_events($e);

function my_after_insert($data)
{

// $data["id"]; will hold new inserted id

}

You can take reference from demos/editing/custom-events.php

Michael answered 11 years ago

Hi Abu,

Whenever I use the line of code:

$grid->set_events($e);

The website doesn't show (fails) is set_events() a new feature??
I purchased the software less than 12 months ago.

Thanks,

Michael

Abu Ghufran answered 11 years ago

Hello,

The set_events() function is from version 1.
Make sure $grid variable is present and set to
$grid = new jqgrid();

If you are using some different variable, you need to call set_events against that var.

Michael answered 10 years ago

Hi Abu,

I've managed to get the screen to display again – my error!
I cannot however get the program to perform a task after a record has been added.

Here is the code:

$e["on_after_insert"] = array("my_after_insert", null, true);
$g->set_events($e);

function my_after_insert($data){

$data["id"]; will hold new inserted id

}

I've also gone to your demo software for "Custom Events" and this also will not perform an event after and record has been inserted – that is not on the server side".

Can you help?

Thanks,

Michael

Abu Ghufran answered 10 years ago

Here is the sample usage:

$e["on_after_insert"] = array("after_insert", null, true);
$grid->set_events($e);

You can code your email logic inside after_insert.
You can also debug it by putting phpgrid_error('test'); inside function. It would prompt the message on grid.

function after_insert($data)
{
/*
These comments are just to show the input $data format
Array
(
[client_id] => 99
[params] => Array
(
[client_id] =>
[name] => Test
[gender] => male
[company] => Comp Test
)

)
*/
ob_start();
print_r($data);
$str = ob_get_clean();
phpgrid_error($str);
}

Your Answer

12 + 18 =

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?