Forum Discussion

NathanCall's avatar
NathanCall
Qrew Trainee
7 years ago

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

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
  • 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
  • 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. 

  • 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.
  • Hi, are you able to post the working example here? I'm running into the same thing where I'd like to include the URL in a Rich Text field but it is not reading my var text in the HTML code.

    • NathanCall's avatar
      NathanCall
      Qrew Trainee
      I have a working example for a formula URL field that I found to work great. For whatever reason, I couldn't' get Javascript to work withint the Formula Rich Text Field after the update to that fields properties that Quick Base did.

      Mine has an IF statement but works either way. I have found that this will reload you on your current page without redirecting you to a different page. It also keeps you in the same spot of the report that you are on which is nice.  Here is my example:

      If(

      [Call Phone Trigger] = false, 

      "javascript:" &

      "$.get('" & 

      URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&apptoken=xxxxxxxxx&_fid_264=true&rid=" & [Record ID#]&

      "',function(){" &

      "location.reload(true);" &

      "});" 

      & "void(0);",

      "javascript:" &

      "$.get('" & 

      URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&apptoken=xxxxxxxx&_fid_264=false&rid=" & [Record ID#]&

      "',function(){" &

      "location.reload(true);" &

      "});" 

      & "void(0);")