I using the following code with version 2023.
I have a field with Name “Starred” Varchar(6) in the same table.
Primary key of table is “Id”.
But it does work.
What could be wrong?
// Page Load event
function Page_Load() {
$this->CustomActions["star"] = new ListAction("star", "Add Star"); // Where "star" is the id and "Add Star" is the caption of the custom action
}
// Row Custom Action event
function Row_CustomAction($action, $row) {
if ($action == "star") { // Check action name
$rsnew = ["Starred" => "Y"]; // Array of field(s) to be updated
$result = $this->update($rsnew, "Id = " . $row["Id"]); // Update the current record only (the second argument is WHERE clause for UPDATE statement)
if (!$result) { // Failure
$this->setFailureMessage("Failed to update record, Id = " . $row["Id"]);
return false; // Abort and rollback
} elseif ($this->SelectedIndex == $this->SelectedCount) { // Last row
$this->setSuccessMessage("All selected records updated.");
}
return true; // Success
}
}
no. I do not see any message.
Debug is enabled.
And no messaged also by debug.
I deleted the entire projekt folder on the web server and regenerated the files.
It should work, as I’ve tried this following code in products table of demo2023 project:This is the code in Page_Load server event under List Page:
$this->CustomActions["star"] = new ListAction("star", "Add Star"); // Where "star" is the id and "Add Star" is the caption of the custom action
This is the code in Row_CustomAction server event under List Page:
if ($action == "star") { // Check action name
$rsnew = ["Discontinued" => "1"]; // Array of field(s) to be updated
$result = $this->update($rsnew, "ProductID = " . $row["ProductID"]); // Update the current record only (the second argument is WHERE clause for UPDATE statement)
if (!$result) { // Failure
$this->setFailureMessage("Failed to update record, ProductID = " . $row["ProductID"]);
return false; // Abort and rollback
} elseif ($this->SelectedIndex == $this->SelectedCount) { // Last row
$this->setSuccessMessage("All selected records updated.");
}
}
return true;
It works properly, as I see this success message: All selected records updated.
thank you for your efforts.
But it is not working for me.
Only your “return true;” is different then the official code.
Even then it is not working for me, when I replace the return true after one curly bracet…
My Db is MariaDB.
Everything else seems to work.
I have a project imported from 2022 into 2023 and my row_customactions are not working.
And in log file and debug no error messages.mpol_ch
You may read the docs about Debug more carefully. Make sure you have enabled all the related advanced setting during development.Also, as said in the docs:
Make sure you have also configured your php.ini to display errors (and log errors if necessary):
error_reporting (int) - set it to E_ALL
display_errors (string) - set it to On
Otherwise there will no errors reported by PHP.
If there is no log, then you should debug by logging the variables in your code to check if your code is correct, e.g.
Log("Row_CustomAction", [
"action" => $action, // Check if $action == "star"
"row" => $row, // Check value of $row["Id"]
"result" => $result // Check if the update is successful
]);
Hi mobhar,
I just put your code on the demo projekt (2023).
// Page Load event
function Page_Load()
{
//Log("Page Load");
$this->setFixedHeaderTable(true, "mh-400px");
$this->CustomActions["star"] = new ListAction("star", "Add Star"); // Where "star" is the id and "Add Star" is the caption of the custom action
}
// Row Custom Action event
function Row_CustomAction($action, $row)
{
// Return false to abort
if ($action == "star") { // Check action name
$rsnew = ["Discontinued" => "1"]; // Array of field(s) to be updated
$result = $this->update($rsnew, "ProductID = " . $row["ProductID"]); // Update the current record only (the second argument is WHERE clause for UPDATE statement)
if (!$result) { // Failure
$this->setFailureMessage("Failed to update record, ProductID = " . $row["ProductID"]);
return false; // Abort and rollback
} elseif ($this->SelectedIndex == $this->SelectedCount) { // Last row
$this->setSuccessMessage("All selected records updated.");
}
}
return true;
}