I want to use a “Row_CustomAction” in List Page Load that execute/run an existing Custom File.
My Custom File is: rechdocx.php
The custom file rechdocx.php is working properly and it is generating a Word Docx file.
With CustomAction “CreateMultiRechnung” I want to create multi outputs for the selected word docs.
Below is my code.
Any recommendation where to start or a better way to go?
// Page Load event
function Page_Load() {
//echo "Page Load";
$this->Lieferadresse->DisplayValueSeparator = " ";
$this->CustomActions["CreateMultiRechnung"] = new ListAction("CreateMultiRechnung", "Create Multi Rechnung", IsLoggedIn(), ACTION_POSTBACK, ACTION_MULTIPLE,"","");
}
// Row Custom Action event
function Row_CustomAction($action, $row)
{
// Return false to abort
if ($action == "CreateMultiRechnung") {
/mpol/rechdocx?Code=$row["Code"]&KNr=$row["Kundenr"]&LAd=$row["Lieferadresse"]&Vorlage=rechnung.docx&ZZTage=30&$row["Id"]=7
}
return true;
}
Hi,
I am generating with custom file rechdocx.php a Word file with help of phpword.
Now, i want call/run the custom file rechdocx.php more than once to generate many word files, when I select more than one rows.
The custom file get the parameters with help of URL.I hope it is clearer now.
There should be no problem at all. Just get the selected records key in Row_CustomAction server event as a comma separated values (assume the primary key field of the table is ID and you’re using >= v2021), for example:
if ($action == "CreateMultiRechnung") {
$multiple_id .= $row['ID'] . ",";
if ($this->SelectedIndex == $this->SelectedCount) { // Last row
$multiple_id = trim($multiple_id ','); // remove the last comma
$this->setMessage('Multiple ID: ' . $multiple_id); // display it to check
header('Location: yourcustomfile?multiple_id='.$multiple_id);
}
}
Then in your Custom File get those multiple id by using Get() global function, explode it, and then process the result as you want.
Hi,
thanks.
But I am trying this way and it does not work.
The expected result is to have a .docx generated.When I call the custom file “Rechdocxsave.php” with app eq ht…/…/rechdocsave then it works.
Is this way correct?
Will it work in this way?
// Row Custom Action event
function Row_CustomAction($action, $row)
{
// Return false to abort
if ($action == "CreateMultiRechnung") {
exec('views/Rechdocxsave.php');
}
return true;
}
Hi,
I am getting with the following code only one record, even multiple rows are selected.
Is there an example for seleced multiple rows?So that I can get for each selected row a call of my file?
// Row Custom Action event
function Row_CustomAction($action, $row)
{
// Return false to abort
if ($action == "CreateMultiRechnung") {
header('Location:mpol/rechdocxsave?Code='.$row['Code'].'&KNr='.$row['Kundenr'].'&LAd='.$row['Lieferadresse'].'&Vorlage=rechnung.docx&ZZTage=30&Id='.$row['Id']);
exit;
}
return true;
}
Your code and your logic is wrong. Please refer the code and the logic that I posted above. I have already tested it before posted to this forum, and I already make sure it works as expected.
Maybe this will make more clear on Row_CustomAction($action, $row).Whatever action you made in ListAction, the return results will be stored in $this->getFilterFromRecordKeys();The working step will be something like
$rows = $this->getFilterFromRecordKeys();
foreach ($rows as $row) {
Row_CustomAction($action, $row); // means Row_CustomAction will execute multiple times.
}
thank you for the hint
Now the code is working but the expected ceration of .docx files are not working.
With “header('Location:mpol/rechdocxsave…” I am trying to generate a word file for each selected row.
Do you have an idea why not?
function Row_CustomAction($action, $row)
{
// Return false to abort
global $multiple_id;
if ($action == "CreateMultiRechnung") {
$multiple_id .= $row['Id'] . ",";
if ($this->SelectedIndex == $this->SelectedCount) { // Last row
$multiple_id = trim($multiple_id, ','); // remove the last comma
$this->setMessage('Multiple ID: ' . $multiple_id); // display it to check
header('Location:mpol/rechdocxsave?Code='.$row['Code'].'&KNr='.$row['Kundenr'].'&LAd='.$row['Lieferadresse'].'&Vorlage=rechnung.docx&ZZTage=30&Id='.$row['Id']);
}
}
return true;
}
Then you need to re-evaluate your code in your Custom File. You should change the logic in there, to loop through those multiple ids, and then generate the .docx files as many as the ids.
Row_CustomAction is fired for each selected row, your code only needs to consider the current row.
You should not use header('Location: …) which means redirecting. To execute code in your file you may use include() or curl(), depending on the code in your file.
HiI have used the following code but the there is no created file.
When I call “http://192.168.33.46/2022/rechnungsbox2022/rechdocxsave” then I a getting a file created.
This is a custom file which generates a docx file with help of phpwork.
Once it works then I will try with parameters.
I am seeing the output with echo but there is no output genereated…
function Row_CustomAction($action, $row)
{
// Return false to abort
global $multiple_id;
if ($action == "CreateMultiRechnung") {
$multiple_id .= $row['Id'] . ",";
$url = "http://192.168.33.46/2022/rechnungsbox2022/rechdocxsave";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
echo $url;
//header('Location:mpol/rechdocxsave');
if ($this->SelectedIndex == $this->SelectedCount) { // Last row
$multiple_id = trim($multiple_id, ','); // remove the last comma
$this->setMessage('Multiple ID: ' . $multiple_id); // display it to check
}
}
return true;
}
To execute code in your file you may use include() or curl(), depending on the code in your file.
If your code uses session variables, curl() won’t work because you did not pass the cookie. You may post the code in /2022/rechnungsbox2022/rechdocxsave for discussion.