Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Before Edit custom code does not run

Questions related to using nuBuilder Forte.
Post Reply
nadir
Posts: 44
Joined: Mon Apr 21, 2025 7:03 am
Has thanked: 5 times
Been thanked: 4 times

Before Edit custom code does not run

Unread post 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
nadir
Posts: 44
Joined: Mon Apr 21, 2025 7:03 am
Has thanked: 5 times
Been thanked: 4 times

Re: Before Edit custom code does not run

Unread post 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.
kev1n
nuBuilder Team
Posts: 4416
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 74 times
Been thanked: 472 times
Contact:

Re: Before Edit custom code does not run

Unread post by kev1n »

Good point, and thanks for figuring that out. We'll look into a cleaner way to handle this going forward.
Post Reply