Weird behavior with Javascript button on report view

  • 0
  • 1
  • Question
  • Updated 2 years ago
  • Answered
I like using the Magic Button app to find code and graphics for buttons for my app. I just copied one and am having multiple weird behaviors. The button I want is to let our staff close-out items on a report.

1. Click on button on the report, it goes to the record and shows it unmodified from the button.
2. I refresh the record and it then shows it as modified as 'Done' per the button.
3. I use the back button to go back to the report, it shows as unmodified still.
4. I refresh the report and the record shows as 'Done'.

I suspect that (1) is caused by the click on the line being captured as a hyperlink to the record first, then secondarily as a click on the button. And (3) is caused by caching, but I'm not used to QB caching info like this, I guess this is related to the Javascript modifying the record instead of yours truly.

My button is a formula/text, I've only really modified it to add a 'if' statement to deactivate it if the status doesn't need to be changed. Skipping the Var declaration of the URL:

If([Status]="Done","Done","<a href=\"javascript:" & "$.get('" & $url &
    "', function(){" & "location.reload();" & "});" &
    "void(0);\"><img src=\"https://images.quickbase.com/si/32/110-touchscreen.png\"></a>")

I could switch to a URL field, but I like being able to disable the button when it it done. Is the behavior I am describing normal, or am I crazy? Or my browser (Firefox)?
Photo of David

David

  • 598 Points 500 badge 2x thumb

Posted 2 years ago

  • 0
  • 1
Photo of Matthew Neil

Matthew Neil

  • 31,438 Points 20k badge 2x thumb
What does your 'var text url=' look like?  Is there a rdr in it?

p.s. You can have the same conditional behavior on formula url fields, just not as pretty.
Photo of David

David

  • 598 Points 500 badge 2x thumb
The 'var text url' declaration in the example Magic Button, and my use, doesn't have an rdr. The magic button seems to be using the 'location.reload()' call. Of course that works fine in the example, does it need a image-onload or something? Final URL of a rendered button:

javascript:$.get('mydomain.qb.com/db/bj8kjp6fp?a=API_EditRecord&rid=870&apptoken=mytoken&_fid_11=Done&_fid_99=02-13-2017%2009:20%20AM',%20function(){location.reload();});void(0);
Photo of David

David

  • 598 Points 500 badge 2x thumb
Okay, I see image-onload being used in Magic Buttons. This is first time using outside of my usual app, must be the problem, I don't have it set up. I'll have to backtrack to add.
Photo of Matthew Neil

Matthew Neil

  • 31,438 Points 20k badge 2x thumb
Try something like this, it should work, and you wont have to use the image onload stuff.
var text URLP= URLRoot() & "db/" & [_DBID_QC] & "?a=API_EditRecord&rid="&[Record ID#]&"&apptoken=xxxxxxxxxxx&_fid_35=1&_fid_43="&URLEncode(Now())&"&_fid_44="&URLEncode(User())
 ;
"javascript:" &
"$.get('" & 
$URLP & 
"',function(){" &
"location.reload(true);" &
"});" 
& "void(0);"
This is a formula URL field, then you can just inject this into any of your formula text buttons.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,482 Points 20k badge 2x thumb
I can't think of a single good reason not to ALWAYS use the image onload technique or another JavaScript injection technique. Placing JavaScript into your QuickBase formulas is guaranteed to cause you problems either immediately or in the near future. It becomes extremely difficult to debug your formulas when you are constantly required to escape characters and are limited to short scripts consisting of just a few statements.

If you set up the image onload technique once you can easily reuse it within the same application with a formula you can conveniently commit to memory:

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

By continuing to cram the JavaScript into QuickBase formulas you are locking yourself out of all the rich features of JavaScript - which are exploding in capabilities and show no signs of slowing down.
(Edited)
Photo of David

David

  • 598 Points 500 badge 2x thumb
Stupid simple task-oriented app I should have been done with a long time ago. So my solution is no javascript! I just made two text-formula fields, one with a rdr to the report (used on the report), and one with rdr to the record (used on the record form). No onload, no js. Instead I just have to remember to modify two buttons, not one, if/when the app changes. And a lesson to read what the heck I am copying that is someone else's work. Cheers!
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,482 Points 20k badge 2x thumb
This is retrograde. If QuickBase moves to a single page application architecture with Mercury I doubt you will able to use rdr in any formulas. I am speculating here but a lot of things could change with Mercury