SELECT res_partner.id,
res_partner.name,
res_partner.x_referral,
account_invoice.state,
account_invoice.id AS idname,
account_invoice.amount_total,
users.bonus
FROM (((res_partner
LEFT JOIN account_invoice_line ON ((res_partner.id = account_invoice_line.partner_id)))
LEFT JOIN account_invoice ON ((account_invoice_line.invoice_id = account_invoice.id)))
JOIN users ON (((res_partner.x_referral)::text = (users.reff_id)::text)))
create:
// ListOptions Load event
function ListOptions_Load() {
$item = &$this->ListOptions->Add(“generatebonus”);
$item->Header = “Generate Bonus”; // Set the column header (for List page)
$item->OnLeft = TRUE; // Link on left
$item->ShowInButtonGroup = FALSE;
$item->ShowInDropDown = FALSE;
$item->MoveTo(0);
}
create:
// Row Custom Action event
function Row_CustomAction($action, $row) {
$rsnew = [“bonus” => 75000]; // 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)
//$result = SendEmail($fromEmail, $toEmail, $ccEmail, $bccEmail, $subject, $mailContent, $format, $charset, $smtpSecure = “465”, $arAttachments = , $arImages = , $arProperties = NULL);
if (!$result) { // Failure
$this->setFailureMessage(“Failed to generate”);
return FALSE; // Abort and rollback
} elseif ($this->SelectedIndex == $this->SelectedCount) { // Last row
$this->setSuccessMessage(“Berhasil Generate Bonus.”);
}
return TRUE; // Success
}
but on web usualy. Failed to generate.
Is a process like this can’t be done in a relation table?
thx
Is a process like this can’t be done in a relation table?
If your database view is updateable, then it should work.
If not, then try to use Execute() (v2020) or ExecuteUpdate() (v2021) global function to execute the UPDATE SQL statement.
For more info and example regarding Execute() or ExecuteUpdate(), please read “Some Global Functions” sub-topic under “Server Events and Client Scripts” topic of PHPMaker Help menu.
function Row_CustomAction($action, $row) {
if ($action == “generatebonus”) {
$rsnew = [“bonus” => 75000]; // 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)
//$result = SendEmail($fromEmail, $toEmail, $ccEmail, $bccEmail, $subject, $mailContent, $format, $charset, $smtpSecure = “465”, $arAttachments = , $arImages = , $arProperties = NULL);
if (!$result) { // Failure
$this->setFailureMessage(“Failed to generate”);
return FALSE; // Abort and rollback
} elseif ($this->SelectedIndex == $this->SelectedCount) { // Last row
$this->setSuccessMessage(“Berhasil Generate Bonus.”);
}
return TRUE; // Success
}
}
im try this code . n still failed
If your database view is updateable, then it should work.
It depends on your Database View supports updateable or not. If not, then try the solution below.
mobhar wrote:
If not, then try to use Execute() (v2020) or ExecuteUpdate() (v2021) global function
to execute the UPDATE SQL statement.
Here, you should be able to update just for “bonus” field in your “users” table. You should be able to identify the user id based on the id value from your Database View via Row_CustomAction server event.
$ result = Execute (“UPDATE account_invoice SET x_referral = ‘67000’ where id = 115157”);
does not work,
But if using the original table, the query works fine … can’t the view run row_customaction with another table update? thanks
oh ok, it’s a shame even though surely a need like this will be widely used in applications.
I hope in the future view can do this kind of thing. thanks for your help
This has nothing to do with PHPMaker itself. You need to handle it by yourself in the related server event.
This condition is actually similar to another case that uses Database View, too. You need to use “UpdateTable” property that belongs to the Table/Page class to decide which table that will be used to update the record, and exclude the unwanted field(s) by using PHP unset().