Forum Discussion
- EOMDeveleporsQrew CaptainI am using now this code but its not prompting.
Can anyone help thanks
If([Maximum Record ID# In]=0,"javascript:alert('You have not clocked in. Please clock in first!')",
var text memo = "javascript:prompt('Enter a brief description of the work done in this session: ', ' ')";
var text url=
URLRoot() & "db/" & [_DBID_TIME_IN_OUTS] & "?a=API_EditRecord&apptoken=myTokenHere&rid=" & URLEncode ([Maximum Record ID# In])&"&_fid_6=Out"&"&_fid_20=" & $memo;
"javascript:" &
"$.get('" &
$url &
"',function(){" &
"location.reload();"&
"});" &
"void(0);") - _anomDiebolt_Qrew Elite>But how do I change the gReqAppDBID to point it to a specific table in my app.
Don't change your formula - you need to change the content of the script in the code page myscript.js. It is a little know fact that you can use any dbid in an application to address a code page URL. For example, all of these URLs in the application QuickBase Support Center point to the same code page:
https://login.quickbase.com/db/6ewwzuuj?a=dbpage&pageid=6
https://login.quickbase.com/db/9kaw8phg?a=dbpage&pageid=6
https://login.quickbase.com/db/6ewwzuuj?a=dbpage&pageid=6
So what you need to do is use the appropriate dbid in your code page script and leave your formula unchanged.- EOMDeveleporsQrew CaptainThanks for your reply. My understanding is that gReqAppDBID gets the table id of the current table. If I need to edit record on table "bnqepesti" how to I write that in the code page. I tried dbid: "bnqepesti" but its not working.
Thanks again for your help.
here is a copy of my current code page:
var apptoken = "cci99s..............tqtfq";
$.ajaxSetup({data: {apptoken: apptoken}});
var description= prompt("Enter a brief description of the work done in this session: ", "");
var dbidTable = "bnqepesti";
var promise = $.get(dbidTable, {
act: "API_EditRecord",
rid: QBU_rid,
_fid_20: description,
_fid 6: "Out"
});
$.when(promise).then(function(){
document.location.href = dbidTable + "?a=dr&rid=" + QBU_rid;
});
- EOMDeveleporsQrew CaptainThanks for your reply. My understanding is that gReqAppDBID gets the table id of the current table. If I need to edit record on table "bnqepesti" how to I write that in the code page. I tried dbid: "bnqepesti" but its not working.
Thanks again for your help.
here is a copy of my current code page:
var apptoken = "cci99s..............tqtfq";
$.ajaxSetup({data: {apptoken: apptoken}});
var description= prompt("Enter a brief description of the work done in this session: ", "");
var dbidTable = "bnqepesti";
var promise = $.get(dbidTable, {
act: "API_EditRecord",
rid: QBU_rid,
_fid_20: description,
_fid 6: "Out"
});
$.when(promise).then(function(){
document.location.href = dbidTable + "?a=dr&rid=" + QBU_rid;
}); - _anomDiebolt_Qrew Elite>My understanding is that gReqAppDBID gets the table id of the current table.
Wrong - gReqAppDBID is the application dbid.
I have no idea what use QuickBase developers intended for the global variable gReqAppDBID. However, it appears to be consistently set the the dbid of the application (not a table dbid). Global variables are actually a bad idea and I am sure they will be purged from the product (as they are on mobile site). However, so long is QuickBase uses them there is no reason not to avail yourself of them for the time being as they can shorten the length of your code. This isn't just a pedantic point as there are other global variables that have the same value and I don't know what they are used for either:var gParentDBID = "bgcwm2m3z";
I use the global variable gReqAppDBID in addressing a code page in an application. It turns out that you can address the same code page using either the application or table dbid. As I idicated previously, all of these URL point to the same code page:
var gReqAppDBID = "bgcwm2m3z";
https://login.quickbase.com/db/6ewwzuuj?a=dbpage&pageid=6
https://login.quickbase.com/db/9kaw8phg?a=dbpage&pageid=6
https://login.quickbase.com/db/6ewwzuuj?a=dbpage&pageid=6
If you are injecting JavaScript into a QuickBase authored page your code should be placed in what is called a IIFE (Immediately Invoked Function Expression):(function(){
This is to prevent variables in your code from interfering with QuickBase's variables. Its their page so we can stomp on variable names they may have chosen. So your code should look like this:
//your code here
})();(function(){
var apptoken = "cci99s..............tqtfq";
$.ajaxSetup({data: {apptoken: apptoken}});
var description= prompt("Enter a brief description of the work done in this session: ", "");
var dbidTable = "bnqepesti";
var promise = $.get(dbidTable, {
act: "API_EditRecord",
rid: QBU_rid,
_fid_20: description,
_fid 6: "Out"
});
$.when(promise).then(function(){
document.location.href = dbidTable + "?a=dr&rid=" + QBU_rid;
});
})();
The convention I use in writing scipt is to use the variable dbid to hold the application dbid and dbidTable to hold the dbid for a table named Table.
Along with some other changes I would write you code like this:(function(){
var dbid = "applicaton dbid";
var dbidTable = table dbid
var apptoken = "application token";
$.ajaxSetup({data: {apptoken: apptoken}});
var description= prompt("Enter a brief description of the work done in this session: ", "");
var promise = $.get(dbidTable, {
act: "API_EditRecord",
rid: QBU_rid,
_fid_20: description,
_fid 6: "Out"
}).then(function(xml) {
console.dirxml(xml);
document.location.href = dbidTable + "?a=dr&rid=" + QBU_rid;
});
})(); - EOMDeveleporsQrew CaptainThanks again for your quick reply.
I am using this code as your directions but when I click the button on the parent table. It freezes an does nothing.
Here is the button formula:
"javascript:" &
"var QBU_rid = '" & [Maximum In Record ID#] & "';" &
"$.getScript(gReqAppDBID + '?a=dbpage&pagename=myscript.js');" &
"void(0);"
here is the myscript.js content
(function(){
var dbid = "bnqepesti";
var dbidTable = table dbid
var apptoken = "I put my token here";
$.ajaxSetup({data: {apptoken: apptoken}});
var description= prompt("Enter a brief description of the work done in this session: ", "");
var promise = $.get(dbidTable, {
act: "API_EditRecord",
rid: QBU_rid,
_fid_20: description,
_fid_6: "Out"
}).then(function(xml) {
console.dirxml(xml);
document.location.href = dbidTable + "?a=dr&rid=" + QBU_rid;
});
})(); - EOMDeveleporsQrew CaptainThere was a semi colon missing. Now it works. Thanks.
I want it to redirect to the url the user is right now either the table or the form. I need to pass the url from the formula but its not working. I did:
"javascript:" &
"var QBU_rid = '" & [Maximum Record ID# In] & "';" &
"var currentUrl = '" & URLRoot() & "db/" & "bnqepesti" & "';" &
"$.getScript(gReqAppDBID + '?a=dbpage&pagename=myscript.js');" &
"void(0);")
But its going to the home page instead of the current page.
I also wanted to add a pic file for the button. I guess I need to add that in the myscript.js page
Thanks again - EOMDeveleporsQrew CaptainI figured it out. I just replaced
document.location.href = dbidTable + "?a=dr&rid=" + QBU_rid;
with
$.get() & location.reload(true);
Can anyone help me with changing the button to a pic from the library. - EOMDeveleporsQrew CaptainThanks Dan for your help.