Hi, I want to delete parent record and related child record.I have used formula, same works fine for parent record deletion but am unable delete related child record.

  • 0
  • 1
  • Question
  • Updated 12 months ago
  • Answered

My current formula works fine for parent record deletion but i am unable to get logic for related child record deletion.

"javascript: if (confirm('Are you sure you want to delete record#: "&[RecordID]&" ?')) { window.open('"&URLRoot()&"/db/"&Dbid()&"?a=API_DeleteRecord&="&[RecordID]&"&rdr="&URLEncode(URLEncode("https://XXXXXXXX/db/XXXX?a=dbpage&pagename=close.html"))&"&apptoken=ct4hv8h...; void('') } else { void('') };"    

Is it possible to delete child record 1st and then parent with single click button from view/edit  mode of the parent records.

Thanks in advance.

Photo of Rahul

Rahul

  • 76 Points 75 badge 2x thumb

Posted 4 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,044 Points 20k badge 2x thumb
Before I answer, I am curious to know what you put in the page close.html.

You should be using a pure script solution and calling QuickBase's API methods using AJAX without loading new pages and subsequently closing them. The response of most of the API methods in QuickBase's API are not intended to be displayed unless they return HTML (most API methods return XML).
Photo of Rahul

Rahul

  • 76 Points 75 badge 2x thumb
Thanks Dan. I kept below code in close.html to close the new window.
<html>

<head>


<SCRIPT language=JavaScript>
function closeit(){
window.close();
}
function refresh(){
opener.location.reload();
}
</SCRIPT>
</head>
<BODY onLoad="closeit()" onunload="refresh()">


</body>
</html>
Photo of Rahul

Rahul

  • 76 Points 75 badge 2x thumb
Dan, The above code is working fine and am able to delete the parent record but i also want to delete related child records. so is it  possible to delete that by adding some extra piece of code?
and  api_delete the records with parameter rid  and unfortunately we are calling this button from parent table so we don't have that here. the only thing we have here is related record id, which is actually the key field of parent table.
so is there a way to get the rid of all child records those are related to parent record and then delete.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,044 Points 20k badge 2x thumb
>The above code is working fine ...

Your are just making the job harder by using your current approach. You should put all your JavaScript code in a user defined page and invoke it with a button that uses $.getScript() to execute the JavaScript. This code should do the job:

Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=460


I would test this in a separate application as both methods API_EditRecord and API_PurgeRecords will not ask for confirmation before deleting the parent / child records. You can of course add you own confirmation logic to the script.
Photo of Niraj Shah

Niraj Shah

  • 214 Points 100 badge 2x thumb
Dan, I am unable to get this script to work for me. I am also trying to create a button which will delete the parent and all child records.
Photo of Rahul

Rahul

  • 76 Points 75 badge 2x thumb
Thanks a ton Dan :+1:
I have implemented the code as you suggested and its working fine  :smile: