Forum Discussion
- _anomDiebolt_Qrew EliteHistorically there have been two methods for creating a new record and immediately performing some additional action such as automatically creating related child records. These two techniques have not been publicly published because they might require lengthy support from the author (me). Now I have created a new technique which I call the Save and Scooby Doo technique which I am publishing because I think it will not require any special support. Here goes:
Save and Scooby Doo ~ Add New Record
https://haversineconsulting.quickbase.com/db/bkjdxnw2x?a=nwr
Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=465
I must say this is my best technique in all of 2016.
UPDATED:
Notes:
- The script adds a hidden <iframe> to the new record page. The <iframe> is initially empty of content but it will be used to receive the response of submitting the New Record form. This may appear odd that you can target when the response of a form submission can go because the normal behavior is to reload the page with the form submission's response. However, just as you can retarget where the response to clicking on a hyperlink can go (a <a> element), you can retarget where an <form>'s response go appear.
- The script modifies the standard New Record Form (name=editform) by adding a target to the <form> pointing to the <iframe>. The net result of these two changes is that when the <form> is submitted the response will be written to the hidden <iframe> the host page will not reload as it normally would.
- When the <iframe> is finished loading the URL is extracted and the [Record ID#] of the newly created record being now displayed in the hidden <iframe> is parsed out can converted to a decimal value.
- We now know the [Record ID#] of the newly created record and we throw up a jQuery UI modal dialog displaying the [Record ID#] value along with an image of Scobby Doo.
- This technique is very general and can be used for a range of tasks where you want to do something further with a newly created record. Typical tasks might be to automatically create various child records or to edit the newly created record with perhaps a different form.
- _anomDiebolt_Qrew EliteFWIW, I have a shorter version that extracts the kRid value from the hidden <iframe> with a single statement so you don't need to use the obe32decode function:
Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=467 - DeanOusterhoutQrew Assistant CaptainNice Dan, I need a flavor of this... I need to fire some more javascript after we have the RID. I am not sure how to modify the sccobyDoo to do that? I tried placing a function call but it doesn't work... I am sure because I don't quite understand how you are making the new page appear? Can you help with how to get the next function to run?
Thanks, Dean
Here is what I tried...
(function(){
var querystring=document.location.search;
if (/nwr/i.test(querystring)) {
$("<iframe>", {id: "QBU_editform", name: "QBU_editform"})
.css({display: "none"})
.appendTo("body")
.on("load", function() {
QBbusyHide();
var rid = this.contentWindow.kRid;
var markup = "";
markup += "<h2>You just created a new record with [Record ID#] = " + rid + " !<h2>";
markup += "<center><img src='http://vignette3.wikia.nocookie.net/hanna-barbera/images/2/24/Scoobydoo.jpg' height='200'></center>";
$("<div>").html(markup).dialog({
title: "Save and Scooby Doo!",
modal: true,
close: function(event, ui) {
testAlert(rid);
document.location.href = gReqDBID + "?a=er&rid=" + rid;
}
});
});
$("form[name=editform]").prop({target: "QBU_editform"});
}
})();
function testAlert(rid) {
alert("in testAlert... so I can start and do whatever I need to now that I have the new record id of "+rid);
} - _anomDiebolt_Qrew Elite
- DeanOusterhoutQrew Assistant Captainperfect... thanks very much... and if after my code I want to go to another page? Can you tell me how to make that happen? :)
- _anomDiebolt_Qrew Elitedocument.location href = "https://www.quickbase.com"; // whatever
- DeanOusterhoutQrew Assistant Captainbeautiful... thanks tons.
- DeanOusterhoutQrew Assistant CaptainI am able to get this all to work, but the user defined variables for [iol] and [/iol] don't work in the text formula. When I try to do [iol]myJavascript.js[/iol] it tells me that [iol] is not a field in the table. I have been able to fully code the solution, but your iol would be soo much nicer to use.
Thoughts? - _anomDiebolt_Qrew Elite[iol] and [/iol] are user defined variables - in the formula language they act as if they are fields available in all tables across the application. The definition of [iol] and [/iol] are defined in this pastie
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=294
The whole point of pushing these two strings into user defined variables is to simplify the useage of the IOL technique since once it is set up you can use it in any table by just defining a new image onload field [-] in the table where you need the enhancement and creating a corresponding module.js user defined page.
Once you go IOL you will never go back! - DeanOusterhoutQrew Assistant Captainso just so I am clear... the name of the variable is [IOL=] and the value is the second line....<img qbu='module'.... ?