-
552 Points
Posted 1 year ago
Ⲇanom the ultimate (Dan Diebolt), Champion
-
29,644 Points
Application Tokens are associated with Applications not individual tables. Additionally, there can be several Application Tokens associated with an Application. Given these two observations it isn't clear what your original question is asking or what you are trying to accomplish.
In any case when you are trying to automate some task across your entire account it can be problematic using the API because there is often no common Application Token to use within your script (unless you manually set this up). In these cases you can still write the script but you have to use non-API methods. This may seem unusual if it is your first exposure to the technique but you can GET or POST to any QuickBase endopoint URL using AJAX methods.
In any case when you are trying to automate some task across your entire account it can be problematic using the API because there is often no common Application Token to use within your script (unless you manually set this up). In these cases you can still write the script but you have to use non-API methods. This may seem unusual if it is your first exposure to the technique but you can GET or POST to any QuickBase endopoint URL using AJAX methods.
-
552 Points
You didn't get my question.
API that gives me DBID w.r.t to table name means I pass table name as the parameter and I get the DBID.
API that gives me DBID w.r.t to table name means I pass table name as the parameter and I get the DBID.
Ⲇanom the ultimate (Dan Diebolt), Champion
-
29,644 Points
So where does the part about "App Token" fit into your reformulated question?
Ⲇanom the ultimate (Dan Diebolt), Champion
-
29,644 Points
> I pass table name as the parameter and I get the DBID.
Like this:
var name = "250 Bottles of Beer on the Form";
$.get("main?act=API_GrantedDBs")
.then(function(xml) {
var dbid = $("dbname", xml).filter(function() {
return $(this).text() === name;
}).next("dbid").text();
console.log(dbid);
})
//output
bj4vxvurn
Like this:
var name = "250 Bottles of Beer on the Form";
$.get("main?act=API_GrantedDBs")
.then(function(xml) {
var dbid = $("dbname", xml).filter(function() {
return $(this).text() === name;
}).next("dbid").text();
console.log(dbid);
})
//output
bj4vxvurn
(Edited)
Ⲇanom the ultimate (Dan Diebolt), Champion
-
29,644 Points
Or this version which employs Async / Await:
(function(){
async function getDBID(name) {
var xml = await Promise.resolve(
$.get("main?act=API_GrantedDBs")
);
var dbid = $("dbname", xml).filter(function() {
return $(this).text() === name;
}).next("dbid").text();
return dbid;
}
var name = "250 Bottles of Beer on the Form";
getDBID(name).then(function(dbid) {
console.log(dbid, name)
});
})();
//output:
//bj4vxvurn 250 Bottles of Beer on the Form
(Edited)
-
552 Points
Thank you so much,
One last question.
Is there any API to get Application ID.
for ex-
I am in Application X. I write some script in order to get Application ID.
One last question.
Is there any API to get Application ID.
for ex-
I am in Application X. I write some script in order to get Application ID.
Ⲇanom the ultimate (Dan Diebolt), Champion
-
29,644 Points
Just dip into one of QuickBase global variables:
gReqAppDBID
gReqAppDBID
-
552 Points
Where I will find this gReqAppDBID Global Variable.
Ⲇanom the ultimate (Dan Diebolt), Champion
-
29,644 Points
It is a global variable on every QuickBase page. Go to any QuickBase page, open up the console and type gReqAppDBID and it will spit out the dbid.
-
552 Points
can I use gReqAppDBID in Formula URL field type?
Ⲇanom the ultimate (Dan Diebolt), Champion
-
29,644 Points
No. You can only use it within JavaScript.
-
552 Points
I have a formula URL field with formula
- URLRoot() & "db/" & Dbid() & "?a=dbpage&pagename=xxx.html&pid=" &[record-id]
when I land to xxx.html
I won't be able to access gReqAppDBID global variable. Any comments?
- URLRoot() & "db/" & Dbid() & "?a=dbpage&pagename=xxx.html&pid=" &[record-id]
when I land to xxx.html
I won't be able to access gReqAppDBID global variable. Any comments?
Ⲇanom the ultimate (Dan Diebolt), Champion
-
29,644 Points
I assumed you were injecting your code into a QuickBase authored page in which case the global is available. However, code pages are completely empty and consist of only the code you explicitly include - so you don't have access to any QuickBase globals nor any libraries such as jQuery unless you load them yourself into the code page.
(Edited)
-
552 Points
Alright,
Any solution you will suggest in order to access Quickbase Globals in the code page.
Any solution you will suggest in order to access Quickbase Globals in the code page.
-
552 Points