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.
Batch Actions
-
- Posts: 26
- Joined: 2013-09-23 14:14
Re: Batch Actions
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.
Re: Batch Actions
Don't know if I got your point. Get URL parameter in PHP: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.
Code: Select all
$job_id = $_REQUEST['filterer_job_id'];
Code: Select all
$job_id = makeSafe((string)Request::val('filterer_job_id', ''));
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
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<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 readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
-
- Posts: 26
- Joined: 2013-09-23 14:14
Re: Batch Actions
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>
}
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>
}
Re: Batch Actions
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
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<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 readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: Batch Actions
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
Tips
- Check parameters with
- Check network traffic (payload and response) in network tab of browser's development tools
- Make use of
Excerpt from AppGini documentation
Code: Select all
function print_mail_labels(table_name, ids){
alert("IDs selected from " + table_name + ": " + ids);
}
- 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 sideKind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<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 readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
-
- Posts: 26
- Joined: 2013-09-23 14:14
Re: Batch Actions
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&
Looks like i may need to use something like URLSearchParams to get the job_id from the url ?filterer_job_id=635&
-
- Posts: 26
- Joined: 2013-09-23 14:14
Re: Batch Actions
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.
-
- Posts: 26
- Joined: 2013-09-23 14:14
Re: Batch Actions
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.
so I want to take the results from the code below and email all the rows returned.
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);
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
}
Re: Batch Actions
Hi,
just put the message text that you create in your code into the $message variable from the code above.
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.
-
- Posts: 26
- Joined: 2013-09-23 14:14
Re: Batch Actions
only sends one record not all them.