This topic is locked
[SOLVED]

custom button, return the id from add popup to client before event

12/25/2021 7:09:11 AM
PHPRunner General questions
U
ustunsoz author

Hi fellow phprunners;

I have created a custom button,

  • client before opens add page of another table,
  • after saving I need to return the new id of saved record to client before event,
  • and then continue to sever event with returned id to process the current table update.

is this possible? would you advise how to wait for returning id on client before.

Thanks in advance for your replies

K
kohle 12/25/2021

Hi,
I am not sure what you try to do. Maybe you explain better in an example.

If your problem is based on a field content there is a way without programming in phprunner
to add values "on the fly" to another table which is connect as lookup to this field.

if there are not many fields on your add page I would

simulate the add page as dialog:

  1. Make a dialog with the fields in the client before event (https://xlinesoft.com/phprunner/docs/about_dialog_api.htm)


  2. Pass the field values to server event


  3. SERVER EVENT:
    Get the unique ID from your record of the main table $button->getCurrentRecord(); /getMasterRecord
    This you need for the update.
    Add with sql the values of the dialog to your table (add page) :
    $sql="insert ......");
    DB::Exec($sql);
    Get lastID
    and make an Update with sql on your main table.
    $sql="update ......where id = unique ID");
    DB::Exec($sql);


  4. In client after normally there is nothing to do, only
    if you want to show a message that the record was added
    or not. (error)



Important:
If your custom button is on an edit page you must exclude this LastID field for update
on the fields tab, or it will be updated after the custom button action again with
the value it had when you open the edit page.

What I know about you idea is:

if you open the "add page" , you are leaving the original page and nothing is triggered anymore in the "old page"
Passing parameters you can do with GET or SESSION variables between pages.

  1. old page (custom button) -> 2) open add page -> open old page

for 1)
Normally I open in a custom button a Link (add page for ex.) in "client after" event.
The parameters I want to pass for this link I get in the server event with for ex. $button->getCurrentRecord(); /getMasterRecord
Additional in the server event you save the unique ID of the old page record in a SESSION variable, ex. $_SESSION["oldpage_id"]

for 2)
In the add page I go to the event "after record added"
there I do the programming what I want to do after the record was added.
I your case get the last id of the added of this record .

Here I make also the update on the old_page table with

$sql=" update old_page_table set id_from_add = ". $lastid. " where id_old_page=". $_SESSION["oldpage_id"];
DB::exec($sql);

After I make a redirect to the old page .

rg
J

U
ustunsoz author 12/25/2021

Thanks kohle,
I am grateful for your time and reply, you've quite well understood the problem but I've already thought of the solution you've advised.
Let me elaborate scenario to make it more meaningful:

The custom button on the list page (not on grid), appears after selecting rows.
The add page is sophisticated, there are some conditional fields that input effects other fields, some fields being hidden etc. Therefore this is not applicable on dialog api.
In the custom button list page, I need to process the add page and after the record is created, The selected rows will become the child records of the newly created add page record.

Therefore, I am looking for a solution to open a pop-up add page on the client before, return the newly created ID to the server event, then update master id on the selected rows.

K
kohle 12/26/2021

Take a look at this :

https://stackoverflow.com/questions/17171589/javascript-open-new-tab-and-wait-for-it-to-close

Lets say you can open the add_page in a modal window and save the new userid in a SESSION variable which you could process in your list page.
Somehow you have to open/reload the listpage again to process the Session variable.

PS: Desktop programming is hard to adapt to web browser.

rg
J.

U
ustunsoz author 12/26/2021

Thank you kohle;

I have tried all possible option but no success. I found the other way arround.

  • I passed the client before empty.
  • Server event: Created parent record, get the id of it and update the child records on same process.
  • I opened edit page in popup at client after, and complete the left over inputs by user...

It becomes more logical because child details coming to popup in the mentime.