Discussions

Expand all | Collapse all

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.

  • 1.  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.

    Posted 10-01-2015 10:49

    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.



  • 2.  RE: 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.

    Top
    Contributor
    Posted 10-01-2015 13:47
    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).


  • 3.  RE: 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.

    Posted 10-01-2015 13:57
    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>


  • 4.  RE: 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.

    Posted 10-01-2015 14:05
    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.


  • 5.  RE: 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.

    Top
    Contributor
    Posted 10-01-2015 14:26
    >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.


  • 6.  RE: 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.

    Posted 04-23-2018 13:01
    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.


  • 7.  RE: 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.

    Posted 10-01-2015 15:13
    Thanks a ton Dan :+1:
    I have implemented the code as you suggested and its working fine  :smile: