How to get javascript to return current URL with "return window.location.href"

  • 0
  • 1
  • Question
  • Updated 3 months ago
  • In Progress
I have a button that I have on multiple reports that when clicked it will edit the corresponding record and then redirect to the record that was just edited. 

However, I would like to return to the same page/report where the button was clicked. I am of the understanding that Rurl() only works with AddGen and does not work with EditRecord. 

This is important because we are using this button to make calls through our dialer. When the button is clicked we want to be returned to the same report we were working on. The button is on multiple reports, so I can't hardcode the return URL in the formula field. 

I know you can run javascript in a Formula Text or Formula URL field, but I cannot get it to run the javascript that should retrieve the URL. Here is the Javascript I am trying to load, but can't figure it out: 

return window.location.href

Here is the code for my button:

"<a href="&URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&apptoken=XXXXXXXXXXX&_fid_264=true&rid=" & [Record ID#] & "&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() & "?act=dr&rid=" & [Record ID#])&">" & "<img width=24 height=24 src=\"https://phoneimage.com">"; & "</a>"

Additionally, I am open to any options to get this to simply send me back to where I was working and not dump me into the record that I just edited. Any suggestions would be helpful. Thanks
Photo of Nathan Call

Nathan Call

  • 110 Points 100 badge 2x thumb

Posted 4 months ago

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

QuickBaseCoach App Dev./Training, Champion

  • 53,240 Points 50k badge 2x thumb
Here is a formula for a URL formula field. (Not a Rich Text formula field)

var Text URL = URLRoot() etc up to & [Record ID#];

//(Sorry, my ipad is not kett8ng me cut and paste. ). Be sure to end the formula variable with a semicolon.

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

This concept here is that you make a formula variable called URL and then that piece of JavaScript will run the URL and refresh whatever page you are on.

You can also probably get it to work with an image too.

If I get a chance I will post that too
Photo of Nathan Call

Nathan Call

  • 110 Points 100 badge 2x thumb
I was able to get this to work like a charm with a Formula URL field, however I since Quick Base does not have "Allow HTML" for Formula URL fields, I cannot get my phone icon to work inside of this field type. Here is what worked for the Formula URL field, without the phone icon. 

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

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

& "&_fid_264=" & URLEncode ([Test3])

& "&apptoken=" & "fgxx3jb5s9nwsc7ua8keuwxq9q";

"javascript:" &

"$.get('" & 

$URL&

"',function(){" &

"location.reload(true);" &

"});" 

& "void(0);"


I have tried to put this inside of a Formula Rich Text field, which I am able to get my phone icon to work, however I cannot get the Javascript function to work properly. I have tired your Formula Rich Text field example but I am not able  to get it to accept "" & $Words & "" . It complains at the end of the formula about the syntax. 


Any idea on how I can get it to load the javascript in either the Formula URL field or Formula Rich text field AND include my phone icon? Everything I have tried has been unsuccessful for getting the image to work in either of those two field types.  


I just talked to Quick Base and they said that Javascript is run in a Formula URL field. not a Formula Rich Text field. 

I can't get the Javascript to run in the Formula Rich text field, and I can't get the image to appear in the Formula URL field. 

(Edited)
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,240 Points 50k badge 2x thumb
I have a working example but have been unable to get it to post in this site as I’m cycling this week and just have my ipad.

Contact me me at QuickBaseCoach.com and I will email you an example.