create parent record on loading of child form

  • 1
  • 1
  • Question
  • Updated 2 years ago
  • In Progress
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
Photo of Shihad

Shihad

  • 496 Points 250 badge 2x thumb

Posted 2 years ago

  • 1
  • 1
Photo of Chris

Chris, Champion

  • 4,390 Points 4k badge 2x thumb
Do you mean to pass parameters via a query string in a URL?
Photo of Shihad

Shihad

  • 496 Points 250 badge 2x thumb
yes
Photo of Chris

Chris, Champion

  • 4,390 Points 4k badge 2x thumb

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?


Photo of Chris

Chris, Champion

  • 4,390 Points 4k badge 2x thumb
Your URL will include the table ID as well so the correct table is targeted.
Photo of Shihad

Shihad

  • 496 Points 250 badge 2x thumb
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.
Photo of Chris

Chris, Champion

  • 4,390 Points 4k badge 2x thumb
Maybe Danimal can help you with jQuery or JavaScript. I cannot.
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();
(Edited)
Photo of Shihad

Shihad

  • 496 Points 250 badge 2x thumb
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

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

Photo of Shihad

Shihad

  • 496 Points 250 badge 2x thumb
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 ?
Photo of Matthew Neil

Matthew Neil

  • 31,438 Points 20k badge 2x thumb
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...
Photo of Shihad

Shihad

  • 496 Points 250 badge 2x thumb
Thanks
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,522 Points 20k badge 2x thumb
>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.
(Edited)