Batch Actions

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
selectsteel
Posts: 26
Joined: 2013-09-23 14:14

Batch Actions

Post by selectsteel » 2022-09-02 20:24

Im trying to use the Batch Action Hook to email out some stuff to our clients. I have created a Batch action and the Javascript function to open up the corresponding php page. The problem is its not sending over the Record Id just the row id's.
I have followed this to the letter and tried many things. https://bigprof.com/appgini/help/advanc ... ch-actions.
I simply want to get the record Id into the Javascript function so I can pass it to the php script I have.

function receipts_batch_actions(&$args) {
return array(
array('title' => 'Rejected Receipts', 'function' => 'email_rejected_receipts', 'icon' => 'archive' ));
This works as expected.

I then created a receipts-tv.js
function email_rejected_receipts(table_name, ids){
alert("IDs selected from " + table_name + ": " + ids);
}

This just gives me the row numbers that I checked. So I have tried alot of different things to get the record ID but nothing works.
I have a php script already to go just need the record Id to pass to it.

selectsteel
Posts: 26
Joined: 2013-09-23 14:14

Re: Batch Actions

Post by selectsteel » 2022-09-05 00:32

I do want to clarify this a little. The Receipts table is a child table of another called Trips when I open Receipts from a Trip the Trip record number is in the URL I just need some way to grab it and use it in my script. mycustomapp.com/receipts_view.php?filterer_job_id=635& i need the job id 635.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Batch Actions

Post by jsetzer » 2022-09-05 03:17

I just need some way to grab it and use it in my script. mycustomapp.com/receipts_view.php?filterer_job_id=635& i need the job id 635.
Don't know if I got your point. Get URL parameter in PHP:

Code: Select all

$job_id = $_REQUEST['filterer_job_id'];
or

Code: Select all

$job_id = makeSafe((string)Request::val('filterer_job_id', ''));
Tip When using values in SQL commands, you got from user input, always use makeSafe($value); before to avoid SQL injection. Never trust user input.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

selectsteel
Posts: 26
Joined: 2013-09-23 14:14

Re: Batch Actions

Post by selectsteel » 2022-09-05 13:25

Thank you as always for your help jsetzer. Im still unsure how to pass the job_id through the javascript function used in the batch action hook?
as soon as I click the Rejected Receipts under the More button the url with the ID is gone.

function receipts_batch_actions(&$args) {
return array(
array('title' => 'Rejected Receipts',
'function' => 'email_rejected_receipts',
'icon' => 'archive'));

receips-tv.js -
function email_rejected_receipts(){
var url = 'rejected-receipts.php?';}

rejected-receipts.php-
<?php
$curr_dir = dirname(__FILE__);
include("{$curr_dir}/defaultLang.php");
include("{$curr_dir}/language.php");
include("{$curr_dir}/lib.php");
$job_id = makeSafe((string)Request::val('filterer_job_id', ''));

/* retrieve the records and display mail labels */
$res = sql( "select * from receipts " .
"where job_id = $job_id AND receipt_checked = ('Rejected')", $eo);
while($row = db_fetch_assoc($res)){
?>
<b><?php echo "Date ". $row['date']; ?></b><br>
<?php echo "City Code: ". $row['city_code']; ?></i><br>
<?php echo "Type: ". $row['type']; ?><br>
<?php echo "Description: ". $row['description']; ?><br>
<?php echo "Amount: ". $row['amount']; ?><br>
<?php echo "Why it was Rejected: ". $row['reject_notes']; ?><br>
}

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Batch Actions

Post by jsetzer » 2022-09-05 13:30

Can you please format your code. That would help us reading and understanding.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Batch Actions

Post by jsetzer » 2022-09-05 13:39

According to the specs, you have already mentioned, your javascript function should receive the primary keys of the selected rows in 2nd parameter.

Excerpt from AppGini documentation

Code: Select all

function print_mail_labels(table_name, ids){
  alert("IDs selected from " + table_name + ": " + ids);
}
Tips

- Check parameters with console.log(ids); in javascript

- Check network traffic (payload and response) in network tab of browser's development tools

- Make use of var_dump($YOUR_VARIABLE) in PHP to see what payload arrives on server side
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

selectsteel
Posts: 26
Joined: 2013-09-23 14:14

Re: Batch Actions

Post by selectsteel » 2022-09-05 14:22

yeah I get receipt ids and table name no problem but I need the parent Id as well to be passed to through the javascript file into the PHP file.
Looks like i may need to use something like URLSearchParams to get the job_id from the url ?filterer_job_id=635&

selectsteel
Posts: 26
Joined: 2013-09-23 14:14

Re: Batch Actions

Post by selectsteel » 2022-09-05 14:37

Well I feel stupid I went back and started all over again and found I had a misspelling in my Sql table and I was using the wrong column name in my sql statement. It all works as expected now. Thanks for your help.

selectsteel
Posts: 26
Joined: 2013-09-23 14:14

Re: Batch Actions

Post by selectsteel » 2022-09-12 13:57

Now that I have the print batch actions script working like its written Im trying to email the rows returned as one email.
The only way I can get sendmail to work is like Jsetzer displays on his site.

Code: Select all

 $mail = [
"to" => "[email protected]",
"name" => "My Name",
"subject" => "App Receipts",
"message" => $message,
"From" => "from@myemail address.com"
]; 
sendmail($mail); 
so I want to take the results from the code below and email all the rows returned.

Code: Select all

  /* retrieve the records and display mail labels */
    $res = sql( "select * from receipts " .
                "where receipt_id in ({$cs_ids})", $eo);
    while($row = db_fetch_assoc($res)){
        ?>
        <b><?php echo $row['CompanyName']; ?></b><br>
        <i>C/O <?php echo $row['city_code']; ?></i><br>
        <?php echo $row['type']; ?><br>
        <?php echo $row['description']; ?><br>
        <?php echo $row['amount']; ?>
        <?php echo $row['notes']; ?><br>
         <hr>
        <?php
    }

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Batch Actions

Post by pbottcher » 2022-09-12 20:30

Hi,

just put the message text that you create in your code into the $message variable from the code above.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

selectsteel
Posts: 26
Joined: 2013-09-23 14:14

Re: Batch Actions

Post by selectsteel » 2022-09-12 21:36

only sends one record not all them.

Post Reply