This topic is locked

Loading Session Variable from ID not working for on newly added row to list page

5/4/2025 1:11:34 PM
PHPRunner General questions
A
asawyer13 authorDevClub member

I have a list page with a button on it.

In the button code, for server I am attempting to save the row ID in a session variable.

$record = $button->getCurrentRecord();
$_SESSION["HeaderID"] = $record["ID"];

This works well on rows that already exist, however if I have just added the row and the list page refreshed to show the new row, it appears at though it doesn't pick up the ID.
It appears to just leave an old value in the session variable.

Can someone tell me what I'm doing wrong?

Thanks
Alan

A
asawyer13 authorDevClub member 5/4/2025

The add is being done from the popup add. When I add the record and return to the list, the list only contains the new row which is fine but then the button doesn't work.

If I close the list page, come back in and search for the row I had added, everything works as it should.

C
copper21 5/5/2025

I have run into issues like this. You may have to do a full reload/refresh of the list page.

https://xlinesoft.com/phprunner/docs/how_to_display_any_page_in_a_popup.htm

Scroll to example #9 for inspiration.

D
druck281 5/6/2025

Possible workaround but it's only going to work after adding one record. If you add multiple rows from the popup, the button will only get the last ID.

On page load for the list page

unset($_SESSION["HeaderID"]; //Make sure there is nothing leftover in this field

Then for your Add page pop in the AfterRecordAdded event, capture the new ID with Database API and set the Session ID from there

$_SESSION["HeaderID"] = DB::LastId();

This is NOT ideal but maybe the thought will trigger you or someone else to come up with something better. Other than that, I think copper21 is right and you will just need to build the list page reload into the Add popup.