This topic is locked

Issue with Popup Not Displaying in PHPRunner 11 - Worked Fine in 10.91

10/12/2024 8:09:44 AM
PHPRunner General questions
J
jcy4nez author

Hi I'm facing an issue after upgrading to PHPRunner 11. I had a button event in PHPRunner 10.91 that worked perfectly for opening a popup window to display order details based on the pedido (order number). The code uses getCurrentRecord() to capture the pedido and worked without any problems in version 10.91.

However, after upgrading to version 11, the same code no longer functions as expected. In some cases, the popup fails to open, and it seems like getCurrentRecord() isn't always able to capture the pedido from the list view. It is obvious that the requested field that I am selected with the click event is a key field.

Here’s the code that worked fine in 10.91 on click event:

Server
$record = $button->getCurrentRecord();
error_log("Record obtained: " . print_r($record, true));

if (isset($record["pedido"])) {
$result["pedido"] = $record["pedido"];
error_log("Pedido found: " . $record["pedido"]);
} else {
error_log("Pedido not found in getCurrentRecord, trying direct query.");

// Get the current record ID
$recordID = $button->getCurrentRecordID();
error_log("Current record ID: " . $recordID);

// Direct query to retrieve the 'pedido'
$conn = $button->getConnection();
$sql = "SELECT pedido FROM fa00 WHERE pedido = '" . $conn->real_escape_string($recordID) . "'";
error_log("SQL Query: " . $sql);
$result_db = $conn->query($sql);

if ($result_db && $data = $result_db->fetchAssoc()) {
$result["pedido"] = $data["pedido"];
error_log("Pedido found via direct query: " . $data["pedido"]);
} else {
$result["pedido"] = null;
error_log("Pedido not found via direct query.");
}

}
Client After
if (result["pedido"] != null && result["pedido"] != '') {
console.log("Pedido found: " + result["pedido"]);
var pedidoID = result["pedido"];
var popup = Runner.displayPopup({
url: "encabezadofact_view.php?editid1=" + pedidoID,
width: 1060,
height: 900
});
} else {
console.log("Pedido not found. Result: ", result);
alert("No order found.");
}

Sergey Kornilov admin 10/12/2024

First of all, you need to make sure your code doesn't use any undocumented functionality. For instance, we do not have $button->getConnection() kind of function in our APIs. You need to use Database API to execute your queries and this is most likely what breaks.

If this still doesn't help, you need to use this guide to figure out what exactly breaks and where:
https://xlinesoft.com/phprunner/docs/troubleshooting_custom_buttons.htm

J
jcy4nez author 10/12/2024

hello Sergey, let's start again. based on the example in the documentation. I have started my code.

img alt

I'm trying to capture the value of Pedido# in a button click event using the getCurrentRecord() method in the Server event. Here is the code I'm using:

img alt

Server:
$record = $button->getCurrentRecord();
$result["PedidoID"] = $record["Pedido#"];

Client After:
var popup = Runner.displayPopup({
url: "encabezadofact_view.php?editid1=" + result["PedidoID"],
width: 1060,
height: 900,
header: 'Detalles del Pedido'
});

Unfortunately, getCurrentRecord() doesn't seem to be capturing the value properly, and the Pedido# field is either undefined or empty when I check the console output. I've tried debugging it further using PHP's print_r($record) but haven't had any luck in retrieving the correct value.

Do you have any suggestions or insight into why getCurrentRecord() might not be returning the expected field value? I'd be grateful for any guidance.

Thank you in advance for your help!

fhumanes 10/13/2024

Hi @jcy4nez,

I leave you this link where I explain how PHP code (in phprunner) can be purified in a very simple way:

https://fhumanes.com/blog/guias-desarrollo/guia-34-metodo-basico-para-depuracion-codigo/

In a transforming version 10.91 to version 11 project, I have a similar problem than you.

Greetings,
fernando

Sergey Kornilov admin 10/14/2024

The latest code does make sense.

When you use print_r($record) in the Server event after getting the data record, what exactly does it print?

Also, I do not see any buttons on your screenshot.