Discussions

Expand all | Collapse all

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

  • 1.  Can't seem to get redirect to work after API Call

    Posted 10-17-2017 15:48
    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.


  • 2.  RE: Can't seem to get redirect to work after API Call

    Posted 10-17-2017 15:54
    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);


  • 3.  RE: Can't seem to get redirect to work after API Call

    Posted 10-17-2017 16:06
    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.


  • 4.  RE: Can't seem to get redirect to work after API Call

    Posted 10-17-2017 16:49
    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


  • 5.  RE: Can't seem to get redirect to work after API Call

    Posted 10-17-2017 16:55
    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);


  • 6.  RE: Can't seem to get redirect to work after API Call

    Posted 10-17-2017 18:07
    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.


  • 7.  RE: Can't seem to get redirect to work after API Call

    Posted 10-17-2017 19:45
    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.


  • 8.  RE: Can't seem to get redirect to work after API Call

    Posted 10-17-2017 17:38
    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


  • 9.  RE: Can't seem to get redirect to work after API Call

    Posted 10-17-2017 18:20
    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?


  • 10.  RE: Can't seem to get redirect to work after API Call

    Posted 10-17-2017 19:49
    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))))))


  • 11.  RE: Can't seem to get redirect to work after API Call

    Posted 10-17-2017 18:02
    Oh wow, at least it was something simple, thank you!