Skip to main content
Question

&rdr="" in JavaScript not working

  • May 17, 2018
  • 0 replies
  • 189 views

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!
This topic has been closed for replies.

  • Registered
  • May 17, 2018
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.

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.

  • Author
  • Registered
  • May 17, 2018
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.

  • Author
  • Registered
  • May 17, 2018
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.

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.

  • Author
  • Registered
  • May 17, 2018
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.

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.  

  • Author
  • Registered
  • May 17, 2018
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?

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.

  • Author
  • Registered
  • May 17, 2018
So, this goes in a Formula-URL field or a Formula-Rich Text field?

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.

  • Author
  • Registered
  • May 17, 2018
Thank you!  I'll get to work on it.

  • Author
  • Registered
  • May 17, 2018
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.

I would have to see your code to help you debug.

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