Discussions

 View Only
Expand all | Collapse all

create parent record on loading of child form

  • 1.  create parent record on loading of child form

    Posted 03-29-2017 13:03
    Hi

    I am loading a quickbase form from another application. The application will pass some parameters to quickbase form. While loading the form i want to catch these parameters in quickbase
    and need to create an entry in another table. After creating the entry i want to load the qb form.

    How can be achieved this?

    Thanks


  • 2.  RE: create parent record on loading of child form

    Posted 03-29-2017 13:05
    Do you mean to pass parameters via a query string in a URL?


  • 3.  RE: create parent record on loading of child form

    Posted 03-29-2017 13:13
    yes


  • 4.  RE: create parent record on loading of child form

    Posted 03-29-2017 13:16

    So, each field in your table has a field ID. The field ID is what QB really references when it writes data.

    The field list view should show you the field ID of each field in your specific table.

    You yourself would use it in a query string thusly::

    "https://.......?_fid_15=text or number&_fid_30=text or number&_fid_22=text or number.... etc..."

    Does this make sense?




  • 5.  RE: create parent record on loading of child form

    Posted 03-29-2017 13:17
    Your URL will include the table ID as well so the correct table is targeted.


  • 6.  RE: create parent record on loading of child form

    Posted 03-29-2017 13:22
    ok..fine
    Let me explain more details.
    suppose the url is https://.......?a=10, I want to catch the parameter 'a' in a java script or something. then using this parameter i want to do a doquery from another table.
    Then the results i want to load in the form.


  • 7.  RE: create parent record on loading of child form

    Posted 03-29-2017 13:24
    Maybe Danimal can help you with jQuery or JavaScript. I cannot.


  • 8.  RE: create parent record on loading of child form

    Posted 03-29-2017 19:38
    Application  -> Dashboard - Settings - variables
    you should see the below variables 
    /iol
    /script
    appID
    iol
    script
    These are the java script variables that can be used in the formula fields in any of your table's fields.

    Step 2: 
    Create formula field
    Type - Formula Text
    formula - [iol] & "custom.js" & [/iol]

    Step 3:
    Add the field from step 2 into the form (this is the form where the application will receive parameters)

    Step 4:
    Create a custom page "custom.js" in application pages and add the below script
    1. read the params
    2. create the parent record
    3. from the response take the record id and reload the form by adding the is param using the fid of the related parent field.  




    Below is the partial code that helps

     function readParams() {
    var params = {};

    var locationObj = window.parent.location.search;
    if(!locationObj){
    locationObj = window.location.search;
    }
    if (locationObj) {
    var parts = window.parent.location.search.substring(1).split('&');

    for (var i = 0; i < parts.length; i++) {
    var nv = parts[i].split('=');
    if (!nv[0])
    continue;
    params[nv[0]] = nv[1] || true;
    params[nv[0]] = decodeURIComponent(params[nv[0]]);
    }
    }
    console.log(JSON.stringify(params));
    return params;
    };

    function createRecordAndReload(){
    var params = readParams();
    //the params var will have all the data from the url

    //refer to https://help.quickbase.com/api-guide/index.html#add_record.html%3FTocPath%3DQuickBase%2520API%2520Ca...
    //make an ajax call using api API_AddRecord and with above params create parent record
    addParentRecord(params);

    //on success of the above ajax call reload the window adding a new param with fid of the related parent field 
    //NOT:
    //when the form loads it will trigger the same script but this time you shouldn't run the above call to create a record. when you see the related parent field id don't execute the above ajax call.
    reloadPage();
    }

    function addParentRecord(params){
    }

    function reloadPage(){
    }

    createRecordAndReload();


  • 9.  RE: create parent record on loading of child form

    Posted 03-30-2017 07:36
    I like your suggestion,

    Suppose the script is successfully run and landed on the form. But, there is a possibility that the user may refresh the page. That time, how can we block the running of script. Then again the parent record will be created. That makes problem.

    Thanks


  • 10.  RE: create parent record on loading of child form

    Posted 03-30-2017 14:42

    I totally see the point

    We can do a check on the params everytime the page refreshes, and if the "new param parent_related_record_id" which we received after creating the parent record is appended(which we are doing on page reload after creating the parent record) and available in the params then don't execute the script.  This check should take care of it.
    Let me know if I mis-understood the concern



  • 11.  RE: create parent record on loading of child form

    Posted 03-31-2017 05:42
    Thanks
    I was thinking an alternative..
    First the application creates the parent record by calling API then it sends the parent recordid to the form.
    Which one is better ?  What do you think ?


  • 12.  RE: create parent record on loading of child form

    Posted 03-31-2017 06:07
    You can do this with native quickbase API, no need for the IOL or script (hopefully).

    Lookup the API guide for "AddRecord" and "DoSaveAdd".

    QB will pass what called a "MasterRecord" variable for the child creation.  Its a tricky work around, but might work for you.  It would take some investigating still.

    ****
    On a different note, any chances you can make the parent AFTER the child record is made, then retroactively connect to the parent?  This can also be done with either some script or a button push.

    Just some ideas...


  • 13.  RE: create parent record on loading of child form

    Posted 03-31-2017 06:18
    Thanks


  • 14.  RE: create parent record on loading of child form

    Posted 03-31-2017 15:47
    >no need for the IOL or script (hopefully).

    It is an anti-pattern to suggest there is no need for using IOL or script. Web pages run on JavaScript and there is no alternative (vbscript was the only alternative and it lost the game to JavaScript over a decade ago). There is no well formed problem that script cannot solve and setting up IOL (or other script injection technique) should be the first thing you do to any application.

    Why monkey around with superfluous formula fields to do repeated lookup and summary fields and create imaginary relationships between tables only to encounter further limitation or additional pain maintain these constructs?

    Accept JavaScript into your heart and all your QuickBase problems will evaporate.