Formula URL or Formula Text Button that will perform an action, without the need to navigate away from the current dashboard/report/record?

  • 1
  • 2
  • Question
  • Updated 1 year ago
  • Answered
Can I create a Formula URL or Formula Text Button that will perform an action, without the need to navigate away from the current dashboard/report/record??

I have several checkboxes/dates/users that are stored via a Formula-Text button (I like to put images on the buttons instead of the normal gray ones). However, when clicked these must navigate away and redirect somewhere.

Is there a way to avoid this, being able to click the button and have it execute the command (API_EditRecord) without having to refresh the page. 
Photo of Carlos

Carlos

  • 654 Points 500 badge 2x thumb

Posted 2 years ago

  • 1
  • 2
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
This format will work on a record or a report.

var text URL = URLRoot() & "db/" & "?act=API_EditRecord&_fid_80=1&rid=" & [Record ID#];

"javascript:" &
"$.get('" & 
$url & 
"',function(){" &
"$.jGrowl('This Item has been put on PO CANCEL snooze', {life: 5000, theme: 'jGrowl-green'});" &
"});" &
"void(0);"

The 5000 means it will display the pop up for 5 seconds before it fades away on its own.

I have never tried this on a dashboard in part because the button needs to know which record to act on.
Photo of Carlos

Carlos

  • 654 Points 500 badge 2x thumb
In this case yes. That's intended. Theres no redirect in the URL so you need to manually refresh to see the changes
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
Chris,
You need to add the application token to the URL.

var text URL = URLRoot() & "db/" & dbid() & "?act=API_EditRecord&_fid_158=1&rid=" & [Record ID#] & "&apptoken=xxxxxxxxxxxxx";
(Edited)
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
But do you want to refresh the Page automatically? If so it's a different JavaScript.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
"javascript:" &
"$.get('" &
$URL &
"',function(){" &
"location.reload(true);" &
"});"
& "void(0);"
Photo of Chris

Chris, Champion

  • 4,390 Points 4k badge 2x thumb
Very good. Thanks, guys. This is good stuff.
Photo of Chris

Chris, Champion

  • 4,390 Points 4k badge 2x thumb

Carlos,

Did you do anything differently to the code to make the buttons work in your reports? I applied the apptoken parameter to the query string and the buttons work with apptokens enabled, but in a report the buttons do not work.

Chris

(Edited)
Photo of Carlos

Carlos

  • 634 Points 500 badge 2x thumb
Chris, no nothing different.

Here's the code to one of the buttons I did:

var text action = URLRoot() & "db/" & Dbid() & "?a=API_editRecord&key="& [Item] & "&_fid_699=1" & "&_fid_700=" & URLEncode(User()) & apptoken=abcdefg1234567;
var text url = "javascript:" & "$.get('" & $action & "',function(){" & "$.jGrowl('Growl notification text goes here', {life: 5000, theme: 'jGrowl-green'});" &"});" &"void(0);";
var text button  = "<a class='Vibrant Alert' href=\"" & $url &"\"" & "> Do action and Growl " &  "</a>";

$button
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
The buttons should work identically on a report or form.
Photo of Carlos

Carlos

  • 654 Points 500 badge 2x thumb
Are you aware of any changes to this? after this weekend's update this no longer seems to be working from reports or records
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
It's working for me.

This is working, for example.

var text Update= URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & ToText([Record ID#])  & "&_fid_188=" & ToText(Now());

var text URL = 
"javascript:" &
"$.get('" & 
$Update & 
"',function(){" &
"$.jGrowl('This Item has been put on PO CANCEL snooze', {life: 5000, theme: 'jGrowl-green'});" &
"});" &
"void(0);";

"<a class='Vibrant Danger' href=\"" & $URL &"\"" & ">Button name goes here" &  "</a>"
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
I modified and used in my report but pressing the button shows no reaction.
my fid is 10 and it's a checkbox. I simply want to be able to press the button in a report to mark the checkbox checked because I don't want to have to use "grid edit" which would render another button I have (to open at the URL of the record in a new window) useless.
var text Update= URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & ToText([Record ID#]) & "&_fid_10=1";
var text URL = "javascript:" &"$.get('" & $Update & "',function(){" &"$.jGrowl(‘Item Marked Completed’, {life: 5000, theme: 'jGrowl-green'});" &"});" &
"void(0);";
"<a class='Vibrant Danger' href=\"" & $URL &"\"" & ">Mark Completed" & "</a>"
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
To test this, I suggest that you make a temporary formula URL field with just this.

URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & ToText([Record ID#]) & "&_fid_10=1"

My guess is that when you click that it will fail on something, likely a complaint about the application token is missing.

I suggest that you then go to the settings for the App  and then Advanced settings and either disable the need for Application Tokens or else create one and include the extra line

URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & ToText([Record ID#]) & "&_fid_10=1"
& "&apptoken=xxxxxxxxxxxx"
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
Thanks Coach. The Formula URL button did show it needed an app token, and now the test button works fine (although it shows the XML result and doesn't finish the button, refresh and return to the same report screen).
So while that line was fixed, the next two don't work either. When I click the button nothing happens, so there clearly are issues with the next two lines of code.

Perhaps I need to load the jGrowl first? I don't see that in this thread but I've toyed with other people's code (like the tabbed forms) and used an "onload" field to load the javascript..I"m a newbie and can't really code in javascript, I can just tweak simple stuff from other people sometimes.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
I know that this will work, but the button will be grey.  I'm not sure that I have working code  to easily post to get the jgrowl to work as a Vibrant colored button.



var text URL = URLRoot() & "db/" & "?act=API_EditRecord&_fid_80=1&rid=" & [Record ID#];

"javascript:" &
"$.get('" & 
$url & 
"',function(){" &
"$.jGrowl('This Item has been put on PO CANCEL snooze', {life: 5000, theme: 'jGrowl-green'});" &
"});" &
"void(0);"
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
Can you post your current code that is not working?
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
This is what I had before your last post in a formula-text button

var text Update=URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & ToText([Record ID#]) & "&_fid_10=1"& "&apptoken=xxxxxxxxx";

var text URL = "javascript:" &"$.get('" & $Update & "',function(){" &"$.jGrowl(‘Item Marked Completed’, {life: 5000, theme: 'jGrowl-green'});" &"});" &"void(0);";

"<a class='Vibrant Danger' href=\"" & $URL &"\"" & ">Mark Completed" &  "</a>"
(Edited)
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
Do I have to onload anything? Does the jGrowl just work?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
No there is no onload required.

I see the problem.  :)

‘Item Marked Completed’, 

Those quotes in your formula are curly  66 99 type quotes that get generated typically by Word.

The need to be the ' kind of  single quote.  ie not ‘ ’ and but a ' and '.
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
ARGH!  That keeps happening to me and I figured out that was happening but thought I fixed them all. Thanks for catching it. In my case it's a mac "Notes" app where I keep all my code. I'll have to stop using it once-and-for-all. Gracias!
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
:) That Syntax to get a jgrowl Vibrant button is particularly difficult.  

I keep my cheat notes for code snippets in QuickBase back where it is easily searchable and always handy when I'm on line developing.
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
It works great....I would just want to get it to refresh the page if possible? Although that would probably make the jGrowl not very useful....
Photo of Carlos

Carlos

  • 634 Points 500 badge 2x thumb
Indeed... Though a "background" refresh would be great, as linked buttons won't reflect changes performed through these jgrowl actions so you always need to refresh before clicking elsewhere
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
:)  One per customer.  You get to choose a page refresh or the pop up, not both.
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
How would I switch to a refresh then?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
Change the middle part to this


var text URL = 
"javascript:" &
"$.get('" & 
$Update & 
"',function(){" &
"location.reload(true);" &
"});" 
& "void(0);";
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
amazing. Thanks.
Photo of Carlos

Carlos

  • 654 Points 500 badge 2x thumb
Anyone know if there are any more "jGrowl-COLORS" available?
I seem to get a yellowish one with no formatting if using any other color name other than jGrowl-green?