Welcome to the nuBuilder Forums!

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

Cannot print table Topic is solved

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

Cannot print table

Unread post by nadir »

Hello,

I want to print a browse form. When I press the print button it shows an empty table with just the table headers. No data. The browse form uses PHP code in "Before Browse" event. The browse form is displayed inside an iframe. Please see the attached screenshots.
screenshot-2.png
screenshot-1.png
Thanks,
Nadir Latif
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Cannot print table

Unread post by kev1n »

Please do these checks:
If you encounter an issue, be sure to check the developer console for errors by clicking the `F12` key on most browsers.
Also open nuDebug results (CTRL+SHIFT+D) and check your (Apache) server logs.
I tried to reproduce the issue on my side, including using a temporary table that is created in the BB event.
However, the print function works without any problems for me.

Could you please share the code/SQL that’s being used in the BB event?
nadir
Posts: 39
Joined: Mon Apr 21, 2025 7:03 am
Has thanked: 4 times
Been thanked: 4 times

Re: Cannot print table

Unread post by nadir »

The developer console, Apache error log and nuDebug all show no errors. Following SQL is being used in the BB event:

Code: Select all

//$currentDate = date("YYYY-MM-DD");
//$currentDate = "2021-11-01";

$currentDate = "#date_filter#";

$select = "SELECT
     attendance_id,
     e.employee_id         AS employee_id,
     e.tbl_employee_name   AS name,
     FROM_UNIXTIME(MIN(a.`timestamp`), '%H:%i:%s') AS time_in,
     IF(
       MAX(CASE WHEN a.`type` = 'OUT' THEN a.`timestamp` END) IS NULL,
       '17:00:00',
       FROM_UNIXTIME(MAX(a.`timestamp`), '%H:%i:%s')
     ) AS time_out,
     ROUND((
    IFNULL(
      MAX(CASE WHEN a.`type` = 'OUT' THEN a.`timestamp` END),
      UNIX_TIMESTAMP(CONCAT('$currentDate', ' 17:00:00'))
    ) - MIN(a.`timestamp`)
  ) / 3600, 3) AS hours_worked,
     IF(
       MAX(CASE WHEN a.`type` = 'OUT' THEN 1 END) IS NULL,
       'Not checked out',
       ''
     ) AS Comments
   FROM attendance a
   JOIN employee     e ON e.employee_id = a.employee_id
   WHERE DATE(FROM_UNIXTIME(a.`timestamp`)) = '$currentDate'
     AND a.`type` IN ('IN','OUT')
   GROUP BY a.employee_id
   ORDER BY e.tbl_employee_name";

nuCreateTableFromSelect('#TABLE_ID#', $select);
The SQL in the BB event uses hash code of a Date object. Could that be causing an issue in the print version.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Cannot print table

Unread post by kev1n »

The Hash Cookies shouldn't cause an issue. Could you also show a screenshot of the Browse SQL / columns ?
(ctrl+shift+f -> Browse Tab)
nadir
Posts: 39
Joined: Mon Apr 21, 2025 7:03 am
Has thanked: 4 times
Been thanked: 4 times

Re: Cannot print table

Unread post by nadir »

Here is the screenshot:
screenshot.png
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Cannot print table

Unread post by kev1n »

nadir wrote: Wed Apr 30, 2025 1:52 pm The SQL in the BB event uses hash code of a Date object. Could that be causing an issue in the print version.
Just to confirm—did you try setting a static Date value instead of relying on the hash code? If so, did that resolve the issue or was the problem still there?

Also, how is the Hash Cookie being set?
It might be worth adding nuDebug($select); just before nuCreateTableFromSelect('#TABLE_ID#', $select); to inspect the generated SQL and confirm whether the Hash Cookie is being correctly initialised.
nadir
Posts: 39
Joined: Mon Apr 21, 2025 7:03 am
Has thanked: 4 times
Been thanked: 4 times

Re: Cannot print table

Unread post by nadir »

I set a static Date value in place of the hash code and that fixed the problem. The print view showed the data. Please see following screenshot:
screenshot.png
I added

Code: Select all

nuDebug($select);
before

Code: Select all

nuCreateTableFromSelect('#TABLE_ID#', $select);
Following SQL statement was generated in the Debug console:

Code: Select all

[0] : SELECT
     attendance_id,
     e.employee_id         AS employee_id,
     e.tbl_employee_name   AS name,
     FROM_UNIXTIME(MIN(a.`timestamp`), '%H:%i:%s') AS time_in,
     IF(
       MAX(CASE WHEN a.`type` = 'OUT' THEN a.`timestamp` END) IS NULL,
       '17:00:00',
       FROM_UNIXTIME(MAX(a.`timestamp`), '%H:%i:%s')
     ) AS time_out,
     ROUND((
    IFNULL(
      MAX(CASE WHEN a.`type` = 'OUT' THEN a.`timestamp` END),
      UNIX_TIMESTAMP(CONCAT('#date_filter#', ' 17:00:00'))
    ) - MIN(a.`timestamp`)
  ) / 3600, 3) AS hours_worked,
     IF(
       MAX(CASE WHEN a.`type` = 'OUT' THEN 1 END) IS NULL,
       'Not checked out',
       ''
     ) AS Comments
   FROM attendance a
   JOIN employee     e ON e.employee_id = a.employee_id
   WHERE DATE(FROM_UNIXTIME(a.`timestamp`)) = '#date_filter#'
     AND a.`type` IN ('IN','OUT')
   GROUP BY a.employee_id
   ORDER BY e.tbl_employee_name
The SQL contains the hash code string '#date_filter#' instead of the Date field value. Looks like the hash code is not being set correctly.
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Cannot print table

Unread post by kev1n »

Also, how is the Hash Cookie being set?
Just to follow up—could you clarify how the Hash Cookie is being set?
nadir
Posts: 39
Joined: Mon Apr 21, 2025 7:03 am
Has thanked: 4 times
Been thanked: 4 times

Re: Cannot print table

Unread post by nadir »

I just added the string

Code: Select all

$currentDate = "#date_filter#";
to the SQL in BB code. date_filter is id of the date control in the parent form
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Cannot print table

Unread post by kev1n »

The date_filter will not be automatically visible in the iframe. You will need to set it manually using JavaScript. For example:

Code: Select all

var iframeWindow = $("#run_iframe_id")[0].contentWindow;
iframeWindow.nuSetProperty('date_filter', '2025-04-29');
Make sure to replace "run_iframe_id" with the actual ID of your iframe element.
If you're using a JavaScript Date object, adjust the date string accordingly.
Post Reply