Automatically save record to child-table

This sub-forum is for discussing all topics related to AppGini Helper JavaScript Library, provided by bizzworxx as a third-party AppGini plugin.
Post Reply
devedix
Veteran Member
Posts: 30
Joined: 2021-04-20 10:44

Automatically save record to child-table

Post by devedix » 2021-05-10 06:55

Hi,
I've been using Appgini Helper to automatically create a new record in the child-table base on the parent-table but it can't automatically save the record to the child-table.
Is it possible to do that using Appgini Helper?

Thanks
Regards,
Edix

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Automatically save record to child-table

Post by onoehring » 2021-05-10 09:34

Hi,

probably Jan will post a much better answer than I can.
As AG Helper is JS, it's "frontend". I do not know of any function that would allow submitting the record.
You could however use JS yourself and create a function that submits the form in the same way the submit button does.

I am not even sure what you mean by you let AG Helper create a new record. Would it make more sense to let PHP create a new record instead?

Olaf

devedix
Veteran Member
Posts: 30
Joined: 2021-04-20 10:44

Re: Automatically save record to child-table

Post by devedix » 2021-05-10 11:19

Hi Olaf.
This is the additional parameter for the action button from the Appgini Helper JS library.

Code: Select all

var id = dv.getSelectedId();
var href = "tasks_view.php?addNew_x=1&filterer_calculation_id=" + id;
Here is the link:
https://appgini.bizzworxx.de/appgini/ap ... n-buttons/

The code work perfectly, I just wonder is there some other code to extend this functionality to save the record as well.

Thanks
Regards,
Edix

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Automatically save record to child-table

Post by onoehring » 2021-05-10 16:07

Hi devedix,

thanks for letting me know. Great to hear, that it works now.
I am not sure what you are doing - ok, it seems, you are calling the page to add a new record - but does it also have some content?
I do not understand, why you are using (or want to use) AG Helper to add a new record (I assume it does hold some content) instead of going the backend way using PHP:
You could use the AG Helper function to call your own PHP script which then inserts a (the) new record into the database and after inserting, returns to your parent record (which will show the new child in the child-registers).

Olaf

devedix
Veteran Member
Posts: 30
Joined: 2021-04-20 10:44

Re: Automatically save record to child-table

Post by devedix » 2021-05-10 17:15

Hi Olaf,
I use the AG helper because the code is so simple, and yes it does have the content I need.
Jan is making an awesome plugin and I really like it.
What I'm doing is auto-create a record in the child-table with the content from the parent table, It has many auto-fill fields that can be created directly from the parent-table.

Btw, I have one more question.
How can I update the value of a field and change the owner of the record from a button?
I try to write an ajax file with this code:

Code: Select all

?php
    $currDir = dirname(__FILE__). '/..';
    include("$currDir/defaultLang.php");
    include("$currDir/language.php");
    include("$currDir/lib.php");
    
    /* grant access to all users who have access to the orders table */
    $od_from = get_sql_from('truckingJobfile');
    if(!$od_from){
        header('HTTP/1.0 401 Unauthorized');
        exit;
    }

    $id = intval($_REQUEST['id']);
    if(!$id) exit;

    sql(" update truckingJobfile set closed='true' where jfID='{$id}'", $eo);

    set_record_owner("truckingJobfile", $id, "admin");
But I don't know how to run it with javascript.

Jan also have this button for executing js but I don't know how to load the ajax file.

Code: Select all

// file: patients-dv.js
var dv = AppGiniHelper.DV;
var actionbuttons = dv.actionbuttons;
var group = actionbuttons.addGroup("Additional Buttons");
group.addButton("Click me!", function () {
  alert("Clicked!")
});
Can you help?

Thanks
Regards,
Edix


pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Automatically save record to child-table

Post by pfrumkin » 2021-05-14 13:13

Hi Edix,

See viewtopic.php?t=4051 for an example of how to call an ajax script. If you google "appgini ajax" for instance, you can get a listing of such forum posts (and more).

Totally agree that the Helper JS library is great but like Olaf said, it's job is front-end and wouldn't have db APIs.

~Paul


devedix
Veteran Member
Posts: 30
Joined: 2021-04-20 10:44

Re: Automatically save record to child-table

Post by devedix » 2021-06-23 07:25

Hi Paul and Olaf,

Thanks for the help, I've managed to insert the record automatically through AJAX.

Thank you very much for your kindness and willingness to help.
Regards,
Edix

Post Reply