Page 1 of 1

Before Edit custom code does not run

Posted: Wed Apr 23, 2025 9:13 am
by nadir
Hello,

I created a launch form and added some Php code to the Before Edit section. The Php code fetches data from database and saves the result in a JavaScript variable. The JavaScript variable is used to display a Google Chart. The Following code is used in Before Edit section:

Code: Select all

$select = "SELECT count(*) as total, workmen.tbl_workmen_name FROM tasks, workmen WHERE tasks.workman_id = workmen.workmen_id GROUP BY workmen.workmen_id;";
$stmt = nuRunQuery($select);

$data = "window.googleChartsData = [['Worker', 'Task Count'],";
while($row = db_fetch_object($stmt)) {
    $data .= "['". $row->tbl_workmen_name . "', " . $row->total . "],";
}

$data .= "];";


nuAddJavaScript($data);
The launch form works fine for globeadmin user but for other users it only shows the Google Chart if the refresh menu button is pressed. I checked the developers console and it showed that nuapi.php does not have the JavaScript variable when the page is initially loaded for non admin users. When the refresh button is pressed the nuapi.php contains the JavaScript variable and the chart shows.

Thanks,
Nadir Latif

Re: Before Edit custom code does not run

Posted: Wed Apr 23, 2025 9:45 am
by nadir
The launch form was being accessed from a button object. I set the record id to -1 in the run tab of the button and that fixed the problem. Now the chart shows for non admin users as well on first try.

Re: Before Edit custom code does not run

Posted: Thu Apr 24, 2025 4:24 pm
by kev1n
Good point, and thanks for figuring that out. We'll look into a cleaner way to handle this going forward.