URL formula to edit a record and "refresh the page"

  • 0
  • 1
  • Question
  • Updated 2 months ago
  • Answered

I regularly use little API URL formula buttons like this one.

var text $CopyStatustoPreviousStatus = blah blah blah ......;

$CopyStatustoPreviousStatus
& "&rdr=" & URLEncode($ReDisplayReport)

That works well when I have a button dedicated to either refreshing the record I am sitting on or refreshing a particular report.


I also use this great technique a lot to not refresh the report (so the user does not lose their place in the report or does not lose their Dynamic filter selections.

var text URL= blah blah blah ....;

"javascript:" &
"$.get('" &
$URL &
"',function(){" &
"$.jGrowl('email Triggered to Prospect', {life: 5000});" &
"});"
&
"void(0);"

But I would love to know how to make a button which will do some blah blah blah stuff and then refresh the screen - that way I could have the same button be used on any report and any record. Ideally it would reload the screen and preserve the user's Dynamic filter selections if they were on a report.


If there a way to modify the code above to incorprate this concept
&"javascript:location.reload(true);"

and not do the growl pop up. ie I'm looking for a button to be able to execute a URL formula which would say edit a record and then refresh whatever screen the user is on. In that situation with a refresh, typically the user's feedback that the button click "took" will be that the report refreshed or the record refreshed, so we don't need or want that jgrowl pop up.


Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 67,780 Points 50k badge 2x thumb

Posted 5 years ago

  • 0
  • 1
Photo of Xavier Fan

Xavier Fan, Champion

  • 450 Points 250 badge 2x thumb
No problem. (channeling you here) =)

Basically - you want to replace this line:

"$.jGrowl('email Triggered to Prospect', {life: 5000});" &


with

"location.reload(true);" &


From the jQuery API documentation for $.get: https://api.jquery.com/jQuery.get/

The function being defined is the success function - that is executed if the request succeeds.

So instead of executing the Growl call in the success function, you execute the page refresh call.

I tested this on a test app, and it works even on reports with dynamic filters set.

Let me know if this works for you.



The formula URL would look something this (I used an EditRecord in my test as an example):

var text URL= URLRoot() & "db/" & [_DBID_TABLE_1] & "?act=API_EditRecord"

& "&rid=" & URLEncode ([Record ID#])

& "&_fid_7=" & URLEncode ([Status])

& "&apptoken=" & "XXXX";

"javascript:" &

"$.get('" &

$URL &

"',function(){" &

"location.reload(true);" &

"});"

& "void(0);"
Photo of Tate Forgey

Tate Forgey

  • 702 Points 500 badge 2x thumb
This is great!  I think I would like the growl notification in addition to the refresh, but I can't seem to get them both to work at the same time. Is that possible?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 67,720 Points 50k badge 2x thumb
As far as I know you can refresh the page or jgrowl.  Not both.
Photo of Tate Forgey

Tate Forgey

  • 702 Points 500 badge 2x thumb
Still awesome!
Photo of Wendy Shoef

Wendy Shoef

  • 660 Points 500 badge 2x thumb
I do both frequently.  Here's my code:

var text action = URLRoot() & "db/" & Dbid() & "?a=API_editRecord&rid=" & [Record ID#] & "&_fid_=1;
var text url = "javascript:" & 
"$.get('" & $action & "',function(){" & 
"$.jGrowl('Growl Message', {life: 1000, theme: 'jGrowl-green'}); " &
"setTimeout(function(){ location.reload(); },1000);" &
"});" &"void(0);";
var text button  = "<a class='Vibrant Primary' href=\"" & $url &"\">My button text</a>";

$button
Photo of greg

greg

  • 0 Points
Works great! Thanks
Photo of gmcroberts

gmcroberts

  • 180 Points 100 badge 2x thumb
how would i do this in reverse, i want the refresh to happen before the URL ?
Photo of Xavier Fan

Xavier Fan, Champion

  • 450 Points 250 badge 2x thumb
Can you explain what you're trying to do?  If you're going to go to the URL anyway - why not go to the URL directly, without the refresh?  What does the initial refresh accomplish?
Photo of gmcroberts

gmcroberts

  • 180 Points 100 badge 2x thumb
I have a parent table that shows in a record a link to records in the child table.  The child table contains cases that a user can assign to them self to work, using a custom "Get" button that shows in the link report.  When they click the "Get" button it changes some values in the child record using API_EditRecord to assign the case to that person.  The problem is, if someone else hits the "Get" button at the same time or moments after that second person will take the case from the first person because the report hasn't refreshed.   If I could refresh first I could test the child record to make sure it's not already assigned and therefore not risk someone getting a case that someone else already has.
Photo of Xavier Fan

Xavier Fan, Champion

  • 450 Points 250 badge 2x thumb
In that case, try this:

var text URL= URLRoot() & "db/" & [_DBID_TABLE_1] & "?act=API_EditRecord"
& "&rid=" & URLEncode ([Record ID#])
& "&_fid_7=" & URLEncode ([Status])
& "&apptoken=" & "XXXX";

"javascript:" &
"location.reload(true);" &
"$.get('" &
$URL &
"');" &
"void(0);"

Here are the key parts of the javascript portion:

"location.reload(true);" - This first does the reload

"$.get('" & $URL & "');" - This uses the $.get function to run the URL.  In this case, you don't need a success function to run after the URL.

Hopefully this does what you want.
Photo of gmcroberts

gmcroberts

  • 180 Points 100 badge 2x thumb
Thanks, however it looks like whether I reload before or after I get the same result.  Basically what is happening is I have a summary filed that tells me what the oldest record # is in the child table.  So let's say it shows record#100 as the oldest, when I click my GET button it gets that record number.  If someone else then hits GET and hasn't refreshed recently it also gets record# 100 for that person.  I was hoping doing the reload first would update the summary field to move to the next record number but apparently it does not.  Any thoughts on how I could achieve this?
Photo of Xavier Fan

Xavier Fan, Champion

  • 450 Points 250 badge 2x thumb
What exactly is your GET button doing?  Is it editing a record?  Inserting a new record (and thus changing the [Maximum Record ID#])?

If [Maximum Record ID#] is a summary field, and you already have access to that summary field from your child record (by looking up the summary field in the parent table), you can insert that [Maximum Record ID#] directly into your URL (to indicate record to edit).

Can you try the following and let me know what you find:

Put the [Maximum Record ID#] as a column in your report.  Then let me know what happens to the [Maximum Record ID#] - before and after you hit the GET button, etc.

From what I've seen, the [Maximum Record ID#] updates right away on refresh - so there's something I'm not understanding about what your app is doing.

Please also outline your table structure - the parent, child table, where the GET button is, what it's doing, etc.
Photo of Babi Panjikar

Babi Panjikar

  • 60 Points
I have the similar requirement where my URL button is a part of report called 'unassigned Queue' which is attached to dashboard of the user role.  We have 50+ users working at the same time and they click on 'Assign To Me' button of the report to get the record assigned to me for further editing.

I also have a quickbase action set on the same table which creates a new record in log table and then a summary field (count of records) in the main table.  I used the if condition to check if child record count is 0 then assign else redirect to home /dashboard page of the user.

Below is the code I used.
"Assign To Me" - Formula URL field

var text URL=
If ( [#Check-Assigned For FLR]<=0,
URLRoot() & "db/"&Dbid()&"?act=API_EditRecord&rid="&[Record ID#]& "&_fid_10=" & URLEncode("Assigned For FLR" ) &  ---- record status field.
"&_fid_12=" & URLEncode(UserToEmail(User())) &  ---- Current User
"&_fid_14=" & URLEncode(UserToEmail(User())) &  ---- Current User
 "&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() &"?a=td")
,
URLRoot() & "db/" & Dbid() &"?a=td");

"javascript:" &
"location.reload(true);" &
"$.get('" &
$URL &
"');" &
"void(0);"

I noticed random results with above code.
- If multiple users click on the button at the same time, anyone gets the records and not the first user who clicked (based on first related child record generated).
- secondly the redirection to home page dosen't happen always. Few users are refreshed to report to show the same results prior to click wherein the record is already been assigned to someone else. 
- The record moves-off the queue when user manually clicks on home page or refreshes the browser page.

Questions:
1) How Do I redirect users back to home page and refresh my report so that record moves-off to the one who clicked first?
2) Is there a way to display message using java script  (something liek oops.. record already picked by different user) and redirect back to refresh queue/home page ?
Photo of Adam

Adam

  • 770 Points 500 badge 2x thumb
Is there a way to make this work where the user's page is refreshed and it keeps a search term in the built in search bar? 

The dynamic filters are nice and all, but my users are currently scanning a bar code into the search bar which filters the report down to 5 or 6 relevant records. They then click URL buttons to update status on a few of these relevant records. 

Every time they click one of my URL buttons, it refreshes the page and even though the search bar is still populated, and I see the search term in the URL, the report does not filter until we hit "Search" (or Enter on the keyboard).

My code is below: 

var text URL = 
URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_7="&URLEncode("Complete");

"javascript:" &
"$.get('" & 
$URL & 
"',function(){" &
"location.reload(true);" &
"});" 
& "void(0);"
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 67,780 Points 50k badge 2x thumb
This technique will leave the screen I disturbed.

Try replacing that JavaScript part with this

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

Choose your words.

The 5000 means 5 seconds for the quiet pop up to fade away.
Photo of Adam

Adam

  • 770 Points 500 badge 2x thumb
This code is working as described.

I think by adjusting the words to include something like "Reload browser to update changes"  I can make this work for my needs. 

Thanks very much for the help.