Redirect or Return the user to the page they were on after API Call in Formula Field

  • 0
  • 1
  • Question
  • Updated 3 years ago
  • Answered

User is on Parent form and needs to delete Child records by clicking the Delete Child button (URL) next to each child in the related report on the form. I want them to stay on the Parent form, click the delete button and have the parent form refresh - without them leaving the page.

Here is my formula that successfully deletes the record but the redirect part is not working, not sure if I should have the formula look at the last URL (which I'm attempting/failing) or should it redirect specifically to the Parent record form.

URLRoot()&"db/"&Dbid()&"?a=API_DeleteRecord&rid="&URLEncode([Record ID#])&"&rdr="&URLEncode(URLRoot()&"db/"&Dbid()&"&z=" & Rurl())&"&apptoken=xxxxx"

Photo of Leanne

Leanne

  • 354 Points 250 badge 2x thumb

Posted 3 years ago

  • 0
  • 1
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 67,760 Points 50k badge 2x thumb
There are a few ways to do this.  Here is one

var text URLONE = URLRoot()&"db/"& Dbid() & "?a=API_DeleteRecord&rid="&URLEncode([Record ID#])

& "&apptoken=xxxxxx";

var text URLTWO = URLRoot() & "db/" & [DBID_of the parent table from Advanced properties] & "a=dr&rid=" & totext([Related Parent]);


&URLONE

& "&rdr=" & URLEncocde($URLTWO) 
Photo of Leanne

Leanne

  • 354 Points 250 badge 2x thumb
Syntax Error:( Formula cannot end with an assignment to a variable declaration.
Anything else I should update in the formula besides the DBID and the Related field?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 67,760 Points 50k badge 2x thumb
Sorry I has a & instead of a $ in that last part before the last URLONE

var text URLONE = URLRoot()&"db/"& Dbid() & "?a=API_DeleteRecord&rid="&URLEncode([Record ID#])

& "&apptoken=xxxxxx";

var text URLTWO = URLRoot() & "db/" & [DBID_of the parent table from Advanced properties] & "a=dr&rid=" & totext([Related Parent]);

$URLONE

& "&rdr=" & URLEncocde($URLTWO)
Photo of Leanne

Leanne

  • 354 Points 250 badge 2x thumb
Unfortunately I'm getting the same response as before - it deletes the record but on the redirect page it says "We can't understand the URL you specified"
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 67,760 Points 50k badge 2x thumb
ya well, no guarantees on good code when I don't test.  :)  I was missing a ? in the line below.

var text URLTWO = URLRoot() & "db/" & [DBID_of the parent table from Advanced properties] & "?a=dr&rid=" & totext([Related Parent]);
Photo of Leanne

Leanne

  • 354 Points 250 badge 2x thumb
I will never complain about free help or free code:)

That was the ticket! Thanks so much for your help!!
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 67,760 Points 50k badge 2x thumb
Glad to help