What is the Save and Scooby Doo Technique?

  • 1
  • 1
  • Question
  • Updated 3 months ago
  • Answered

I heard there is a brilliant new Save and Do type technique called Save and Scooby Doo technique. Does anyone know how it works or where I can see a demo of it?

Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb

Posted 3 years ago

  • 1
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
Historically 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:

  1. 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. 
  2. 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.
  3. 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.
  4. 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.
  5. 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.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
FWIW, 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
Photo of Dean

Dean

  • 708 Points 500 badge 2x thumb
Nice 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=&#039;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);

}
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
Please post code to a pastie to is it easy to read.

http://pastie.org/10712485
Photo of Dean

Dean

  • 708 Points 500 badge 2x thumb
perfect... thanks very much... and if after my code I want to go to another page?  Can you tell me how to make that happen?  :)
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
document.location href = "https://www.quickbase.com"; // whatever
Photo of Dean

Dean

  • 708 Points 500 badge 2x thumb
beautiful... thanks tons.
Photo of Dean

Dean

  • 708 Points 500 badge 2x thumb
I 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?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
[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!
Photo of Dean

Dean

  • 708 Points 500 badge 2x thumb
so just so I am clear... the name of the variable is [IOL=] and the value is the second line....<img qbu='module'.... ?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
The names of the variables are "iol' and "/iol" *without* the quotation marks. When you use them in formulas you write something like this:

[iol] & "module.js" & [/iol]

or

[iol] & "moduleTable.js" & [/iol]

Again the whole point of using [iol] and [/iol] is to make using the IOL technique (repeatedly - throughout the application) as easy as possible.
Photo of Dean

Dean

  • 708 Points 500 badge 2x thumb
Ok... all is now working... excellent... thanks very much.  The nice part of this is that I can now use the standard save button without creating my own.  This only seems to call the script when it is a nwr.  Can it also be used for an edit record... er?
Photo of Dean

Dean

  • 708 Points 500 badge 2x thumb
and not having to create my own buttons.
Photo of Dean

Dean

  • 708 Points 500 badge 2x thumb
of course... we already know the RID... but I was thinking about calling other functions...
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
You can use the IOL technique on any page were you can get the [-] field to be included. Once included the module.js file will run and you can detect what type page you are on by using the template in this pastie:

https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=293

Also you can further control if the [-] is included in a form by selecting the option "Display when this form is used for:  edit, add, view ".
Photo of Dean

Dean

  • 708 Points 500 badge 2x thumb
ok... so that is pretty neat... so you solved the problem of getting the RID. Now I realize, by using this method, instead of having my own button where I code the formula, I am now missing some values from the form?  Can I still pass values into this process?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
It would be best to ask a new question as we are wondering away from the original post and I can earn more forum points which I can redeem for valuable merchandise at the QuickBase store and overtake Mark on the leaderboard.
Photo of Dean

Dean

  • 708 Points 500 badge 2x thumb
:)  Ha... I wondered why you were so incredibly generous with your answers...  of course...  I do appreciate all the help.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
> ... so incredibly generous with your answers ...

The only way to become an expert is to practice. I invest a lot of time learning the latest web and programming technologies and most of the well formed questions here in the forum have straightforward answers.
Photo of Dean

Dean

  • 708 Points 500 badge 2x thumb
Morning Dan,  I tried the ScoobyDoo on my firefox at work, and an IE browser, and both are now running all code after the .on("load"... both when the page loads and when the save is clicked.  How can I modify it so that it will run a subset of the code at load(like loading javascript includes), but run different code when the save button is clicked?  I was going to do a pastie but am blocked at work... I should be able to do that later.  Dean
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
Please post your question in a new thread since you are beyond the Scooby Doo. If it involves script run it through http://jsbeautifier.org/ (with two spaces indention) and paste it into pastie http://pastie.org/ (and select JavaScript as the language). Try and post the minimal amount of code that is relevant to the question at hand.
Photo of John

John

  • 0 Points
If I put this on an edit form page, is there a way to capture the previous value of the field?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
Yes.

But  the previous values of a field is actually stored in the edit page form in a hidden field named _oval_fid_6.
oval stands for "old value" which is actually the "current value" until the form  is actually submitted.
Photo of John

John

  • 0 Points
I have run into a snag with grabbing old and new values when it comes to the checkbox. It seems the new value of the checkbox input field is always "on"? Do you know a way to get the new checkbox value when I uncheck?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
This code will return true if the check box is checked and false otherwise:

$("#_fid_6").is (":checked")

In other words you don't use $("#_fid_6").val () to get the value of a checkbox.