Forum Discussion

RahulRahul's avatar
RahulRahul
Qrew Member
10 years ago

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.

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.

  • 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).
  • 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>
  • 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.
  • >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.
    • NirajShah1's avatar
      NirajShah1
      Qrew Cadet
      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.
  • Thanks a ton Dan :+1:
    I have implemented the code as you suggested and its working fine  :smile: