Forum Discussion

JordanBeatty1's avatar
JordanBeatty1
Qrew Captain
8 years ago

Can't seem to get redirect to work after API Call

I'm using the following:
var date RightNow = Today(); 
var text Close = "CLOSED";
var text URLONE = URLRoot() & "db/" & Dbid() & "?act=API_EditRecord" 
& "&rid=" & [Record ID#] 
& "&_fid_18=" & $Close
& "&_fid_23=" & $RightNow;
var text URLTWO = URLRoot() & "db/" & [_DBID_ACTIVITY_LOG_DAVE] & "?a=API_AddRecord"
& "&_fid_47=" &URLEncode ([Record ID#]) 
& "&_fid_50=" &URLEncode([Company Name (ref)]) 
& "&_fid_97=" &URLEncode([User #]) 
& "&_fid_31=" &URLEncode([Now]) 
& "&_fid_22=" &URLEncode("Stuff")
& "&_fid_11=" &URLEncode("More Stuff")
& "&_fid_12=" &URLEncode("0.05");
var text URLTHREE = URLRoot() & "db/" & Dbid() & "a=dr&rid" & [Record ID#];
$URLONE
&"&rdr=" & URLEncode($URLTWO)
&URLEncode("&rdr="&URLEncode($URLTHREE))
Although I can't seem to get the third URL to work so I stay on the same page. The actual use of the button is that, you click it and it updates the current parent records you are in. Creates the cookie cutter child record, then I would like to remain in the parent record.
  • MCFNeil's avatar
    MCFNeil
    Qrew Captain
    Does the edit and the add record portion work?  It looks like you might need an apptoken.

    Also, rather than redirecting to the parent, try just have the page refresh; (similar to this)

    "javascript:" &"$.get('" & $URL & "',
    function(){" &"location.reload(true);" &"}); " & "void(0);
  • The first two API calls are working. I was ending up on the XML post with error code 0 telling me it worked.  I removed URLTHREE, and tried replacing the bottom with:

    "javascript:" &"$.get('" & 
    $URLONE
    &"&rdr=" & URLEncode($URLTWO) &
    "',function(){" &
    "location.reload(true);" &
    "});" 
    & "void(0);"&
    "}"
    Though, I have a feeling I put the reload in the wrong spot as neither of the calls work now, or is the page refreshing.
  • So now I have:

    var date RightNow = Today(); 
    var text Close = "CLOSED";

    var text URLONE = URLRoot() & "db/" & Dbid() & "?act=API_EditRecord" 
    & "&rid=" & [Record ID#] 
    & "&_fid_18=" & $Close
    & "&_fid_23=" & $RightNow;

    var text URLTWO = URLRoot() & "db/" & [_DBID_ACTIVITY_LOG_DAVE] & "?a=API_AddRecord"
    & "&_fid_47=" &URLEncode ([Record ID#]) 
    & "&_fid_50=" &URLEncode([Company Name (ref)]) 
    & "&_fid_97=" &URLEncode([User #]) 
    & "&_fid_31=" &URLEncode([Now]) 
    & "&_fid_22=" &URLEncode("Stuff")
    & "&_fid_11=" &URLEncode("More Stuff")
    & "&_fid_12=" &URLEncode("0.05");

    "javascript:" &
    "location.reload(true);" &
    "$.get('" & 
    $URLONE
    &"&rdr=" & URLEncode($URLTWO) &
    "');" &
    "void(0);"

    The page is reloading but now neither of the API calls are working
    • MCFNeil's avatar
      MCFNeil
      Qrew Captain
      I'm jumping into a meeting, but a quick idea.

      try adding an app token
      &apptoken=xxxxxxx

      Also try combining the two URLs before inserting to the javascript;

      var text URLMaster=$URLONE&"&rdr=" & URLEncode($URLTWO);
    • MCFNeil's avatar
      MCFNeil
      Qrew Captain
      The reason I like going the 'refresh' route, rather and the rdr to a specific page, is it allows you to use the button on reports or dashboards.  So you can easily perform the action, and continue where you left off.
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      Matthew
      I agree that the refresh is better but I have always struggled with getting a stupid simple syntax to work when having multiple nested redirects.

      Have you tested your code above?  I will give it a try when I get a chance.
  • Jordan, your original method was correct and will work.

    The problem is here

    var text URLTHREE = URLRoot() & "db/" & Dbid() & "a=dr&rid" & [Record ID#];

    it needs to say ....  & "a=dr&rid=" & [Record ID#];

    Missing the = after rid
    • JordanBeatty1's avatar
      JordanBeatty1
      Qrew Captain
      I think the issue I'm having now is nesting. I had expanded it to:

      var date RightNow = Today(); 
      var text Close = "CLOSED";

      var text URLONE = URLRoot() & "db/" & Dbid() & "?act=API_EditRecord" 
      & "&rid=" & [Record ID#] 
      & "&_fid_18=" & $Close
      & "&_fid_23=" & $RightNow;

      var text URLTWO = URLRoot() & "db/" & [_DBID_ACTIVITY_LOG_DAVE] & "?a=API_AddRecord"
      & "&_fid_47=" &URLEncode ([Record ID#]) 
      & "&_fid_50=" &URLEncode([Company Name (ref)]) 
      & "&_fid_97=" &URLEncode(8) 
      & "&_fid_31=" &URLEncode([Now]) 
      & "&_fid_22=" &URLEncode("Stuff)
      & "&_fid_11=" &URLEncode("More Stuff")
      & "&_fid_12=" &URLEncode("0.05")
      & "&_fid_13=" &URLEncode("False");

      var text URLTHREE = URLRoot() & "db/" & [_DBID_TASKS] & "?a=API_AddRecord"
      & "&_fid_36=" &URLEncode ([Record ID#]) 
      & "&_fid_39=" &URLEncode([Company Name (ref)]) 
      & "&_fid_14=" &URLEncode([Current User])
      & "&_fid_19=" &URLEncode([Associated Admin])
      & "&_fid_8=" &URLEncode([Today])
      & "&_fid_121=" &URLEncode("False")
      & "&_fid_7=" &URLEncode("Lots of Stuff");


      var text URLFOUR = URLRoot() & "db/" & Dbid() & "a=dr&rid=" & [Record ID#];

      $URLONE
      &"&rdr="&URLEncode($URLTWO)
      &URLEncode("&rdr="&URLEncode($URLTHREE))
      &URLEncode("&rdr="&URLEncode("&rdr="&URLEncode($URLFOUR)))

      Though, I am still ending up the XML post. Did I nest this incorrectly?
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      Here is the correct syntax.  Your last line is not correct.



      $URLONE 
      & "&rdr=" & URLEncode($URLTWO)
      & URLEncode("&rdr=" & URLEncode($URLTHREE))
      & URLEncode(URLEncode("&rdr=" & URLEncode($URLFOUR)))



      here is a longer version for future use


      $URLONE 
      & "&rdr=" & URLEncode($URLTWO)
      & URLEncode("&rdr=" & URLEncode($URLTHREE))
      & URLEncode(URLEncode("&rdr=" & URLEncode($URLFOUR)))
      & URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLFIVE))))
      & URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLSIX)))))
      & URLEncode(URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLSEVEN))))))