"&rdr=" in JavaScript not working

  • 0
  • 1
  • Question
  • Updated 6 months ago
  • In Progress
Here is my JavaScript code:

var date = new Date();
var yr = date.toDateString().substr(-2);
var mo = date.getMonth()+1;
var d = date.getDate();

var b = kRid;

console.log(kRid);

var URLONE = document.location.href = "https://ME.quickbase.com/db/DBID?act=API_EditRecord&rid="+kRid+"&_fid_...; "+d+", "+yr+" &_fid_10=Changed Project";

var URLTWO = document.location.href="https://ME.quickbase.com/db/DBID?a=er&rid="+(b);

$URLONE

& "&rdr=" & URLEncode($URLTWO)

console.log(b-1);

If we forget about using var URLONE & var URLTWO and instead test each of these lines separately, they work.  Using the first line alone, it edits the current record, gives me the console.log(b-1) which is one number less than the current record number (just for testing), but after doing that it I get the Success message.  So I hit the 'back' button and I can see the current record has been edited.  Using the second line alone, it brings the current record into its Edit mode, and I also get the correct console.log(b-1) confirmation that my code has gone its full length.  But, when I try to run the two lines concurrently, it seems to skip the first line (ie it doesn't change the fields per my request) and only brings me to the edit screen for the current record.  And, it does not give me the console.lot(b-1) confirmation.  PS - using var b = kRid has been part of my testing.  It works whether I use kRid or b, but I haven't cleaned things up yet.

Please help.  I'm so close to my goal I can taste it.  Thank you!
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb

Posted 6 months ago

  • 0
  • 1
Photo of Matthew Neil

Matthew Neil

  • 31,438 Points 20k badge 2x thumb
Not sure if this helps, but I don't think you can use JS elements in an RDR because they only execute the first time and don't work after the RDR.  

Try adjusting the element types so they don't use JS but more common QB language.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
I agree with Matthew.

I have an app in the exchange called URL formuals for Dummies.  That might help you understand common QuickBase URL formulas.

You obviously have a coding background and we need to dumb you down a notch or two to the low code / no code world.
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb
LOL - I've spent a lot of time with URL for Dummies and also Magic Buttons, but I still can't get just what I want.  But, thank you for the compliment.  I really don't have a coding background.  I flunked Fortran in 1969, but I have done a fair amount with dBase II, dBase III (years ago) and later a little bit with MSAccess.  I know what I want to do, I'm just getting a little stuck in the weeds.
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb
I think I'm getting caught between QB & my JavaScript pages.  It seems like I need to go one way or the other.  I get my QB button to bring us my JS page, but I can't then go back to finish things off in the QB formula field.  There are things I need to do that straight QB won't do, so I have to learn to get JS & QB to play together nicely.
Photo of Matthew Neil

Matthew Neil

  • 31,418 Points 20k badge 2x thumb
If you are going to call a code page, then have all the redirect logic in the code page, and have any stacked actions be executed in one stop.  Then you can keep the button simple.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
Hmm, Fortran in 1969.  
Do I=1,10.
....

enddo

That is all I remember from Engineering.  First year engineering we still had punch cards and slide rules.  I still have my Keuffel & Esser slide rule.  So I'm vintage, like you must be.

Maybe just say in plain english words what you want to happen when you push the button.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,302 Points 20k badge 2x thumb
I use my Spirule and Texas Magnum every day:


The Enigmatic Spirule
http://www.nzeldes.com/HOC/Spirule.htm


World's Longest Slide Rule: Texas Magnum
It measures 352 feet long, weighs 300 pounds and takes three men to slide.
http://www.neatorama.com/2006/09/22/worlds-longest-slide-rule-texas-magnum/
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb
LOL.  Mine is a Pickett.  It's in my drawer with a bunch of other old stuff.

Our app is for generating technical pricing quotations for windows and doors.  We frequently revise our quotes as sizes change, etc, and we also copy old quotes to use as the basis for new quotes.  But we want to retain the old quotes without altering them.  So, we want to copy a parent and its children, and then change the date to new Date() and change the Quote # from 18042501 to 18042501A (revision) or 18051701 (copy), and then return to the revised or copied quote to make the rest of the edits.  So, at the moment, I have one button that goes to a JS page and does a copyMasterDetailButtonHandler to copy the current quote and its line items, and another button (above) that takes the copy and changes its date.  I'm now trying to get it to redirect to the edit screen for the copy, and then I'll figure out how to update the Quote #.  After that, I want to see if I can combine the two buttons into one.  I got into JS because our Quote #s rearrange new Date(), and add 01, 02, etc to the end and then reset back to 01 the next day.  I got all that to work for generating new quotes from scratch, but I also need to get it to work for revisions and copies and I couldn't get it to work in straight QB.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
My approach with a native solution and no code pages would be two clicks.  i just did that last night for a client

var text URLONE= URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_50=" // blank out copy of indicator
& "&_fid_15=" & ToText(Today())  // set date to today
& "&_fid_31=0" // uncheck Completed
& "&_fid_40=0"; // uncheck Reviewed




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

var text Words = "<b><font size=6><font color=red>Click here to reset date and checkboxes"; 

If([Copy Of Indicator used in Copy Master Detail]<>"",

"<a href=" & $URL & ">" & $Words & "</a>").



when you use the copy master detail, it write Copy Of ... into  field.  So I use that to detect that the recored has just been duplicated and then ask the user to click to clear the fields.  
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb
Thank you for that.  I'll play with it later today and see where it takes me.  Is there a resource where I can find out what "javascript:" & , "$.get('" &, and & "void(0);"; are for?
Photo of Rob White IV

Rob White IV

  • 936 Points 500 badge 2x thumb
 for In order to run JavaScript from the browser via URL, you have to preface it with "javascript:".  For example, copy / paste the following into your browser address bar and you might get the message alerted to you.  Depends on browser security settings.  Some will block this type of thing by default for security purposes. 

javascript:alert("Hello");

See https://stackoverflow.com/questions/4163879/call-javascript-function-from-url-address-bar/4163956 for some extra info.  

As far as the 
$.get()
bit, that is most likely shorthand for an AJAX call using the JQuery library, which I believe is loaded in the background for you via QuickBase itself as a dependant for site functionality.

See https://api.jquery.com/jQuery.get/ for more.  

Hope that helps direct you to some extra credit studies when you find the time.  
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb
Thank you, Rob!  I think that's another part of this puzzle I'm missing.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
I can't really help you with that.  I just copy and paste that code and it runs the formula variable called URL and refreshes the page.
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb
So, this goes in a Formula-URL field or a Formula-Rich Text field?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
The example I posted was for a formula Rich text field as it makes a hyperlink.  The alternative would be to just have a red URL formula button as a formula URL field.

I that case it would be a simpler formula

var text URL= URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_50=" // blank out copy of indicator
& "&_fid_15=" & ToText(Today())  // set date to today
& "&_fid_31=0" // uncheck Completed
& "&_fid_40=0"; // uncheck Reviewed


If([Copy Of Indicator used in Copy Master Detail]<>"",

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


If it wuz me, I would just do the two click method, get 'er done and move on to the next thing on my long todo list.
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb
Thank you!  I'll get to work on it.
Photo of Ken Casser

Ken Casser

  • 582 Points 500 badge 2x thumb
Not to drag you farther down this road but, how do I make a Formula-Rich Text field into a hyperlink?  I don't see an option to make this field into a button and it just sits there.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
I would have to see your code to help you debug.

If you start with just a formula URL button there is less code.