Can you test a URL formula to determine if a web page is valid?

  • 0
  • 1
  • Question
  • Updated 5 years ago
  • Answered

I have a URL formula that redirects users to our document library (outside Quickbase) based on the record they are on in Quickbase. However some of our locations do not have documents in the library so if that location does not exist in the library and the URL dumps the user at the ROOT of the library. I would like to dump the user to another area if the location does not exist in the library.

Current structure of the library is:

Root/Chain/location

Thanks!

Robert

Photo of Robert

Robert

  • 210 Points 100 badge 2x thumb

Posted 5 years ago

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

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
Photo of Robert

Robert

  • 210 Points 100 badge 2x thumb
Hi Dan!
Thanks for the reply.
getting an error that says..
A variable declaration must be followed by a type.

Thanks!

Robert
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
When I paste the code into the JavaScript panel of jsfiddle.net and click JSHint it tells me the code is perfectly valid.

Check you own code in this manner.

See screenshot.
Photo of Robert

Robert

  • 210 Points 100 badge 2x thumb
I added "Text" after var... var Text url1 =
And that error went away...
But now QB says "There are extra characters beyond the end of the formula."
$  .ajax({
  url: url1,
  success: function(){
    document.location.href =  url1;
  },
  statusCode: {
    404: function() {
      document.location.href = url2;
    }
  }
});
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
I think there is a misunderstanding. You don't paste the script directly into the formula. You put the code in a user defined page named myscript.js and use a URL formula field such as this to invoke it:


"javascript:$.getScript('yourdbid?a=dbpage&pagename=myscript.js');void(0);"


When the user clicks on the formula URL the script is executed.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,204 Points 20k badge 2x thumb
Here is any easy way to set up the formula URL field that when clicked will run your JavaScript.

1) Create two user defined variables named [script] and [/script] with the following definitions:

[script]=

javascript:$.getScript(gReqAppDBID+'?a=dbpage&pagename=

and
[/script]=

');void(0);

2) Create a user defined page named myscript.js and place your JavaScript in this page. You should probably just put an alert statement in this page to start with to test you have everything set up correctly.
3) For every place you want to invooke the script write a formula URL with the following definition:
[script] & "myscript.js" & [/script]

You probably want to configure this field so it displays as a button.
4) If you need another formula URL field that runs JavaScript just repeat steps 2 and 3 above as your application already has [script] and [/script] set up.
Pastie Database https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=252