Page 1 of 1

Automatically save record to child-table

Posted: 2021-05-10 06:55
by devedix
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

Re: Automatically save record to child-table

Posted: 2021-05-10 09:34
by onoehring
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

Re: Automatically save record to child-table

Posted: 2021-05-10 11:19
by devedix
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

Re: Automatically save record to child-table

Posted: 2021-05-10 16:07
by onoehring
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

Re: Automatically save record to child-table

Posted: 2021-05-10 17:15
by devedix
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

Re: Automatically save record to child-table

Posted: 2021-05-14 05:44
by onoehring
Hi,

sorry, can not help here.
Olaf

Re: Automatically save record to child-table

Posted: 2021-05-14 13:13
by pfrumkin
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

Re: Automatically save record to child-table

Posted: 2021-05-14 15:14
by onoehring
Hi,

talking about an API for AG, you should check this: https://github.com/rafinhacarneiro/appgini-api
(check out the links google returns in the forum: https://www.google.com/search?q=https%3 ... ppgini.com

Olaf

Re: Automatically save record to child-table

Posted: 2021-06-23 07:25
by devedix
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.