Forum Discussion
VamsikrishnaSol
9 years agoQrew Member
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.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();
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.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();
- ShihadShihad9 years agoQrew CadetI 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 - VamsikrishnaSol9 years agoQrew Member
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 - ShihadShihad9 years agoQrew CadetThanks
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 ?