Prevent Deleting a Master Record if it has Child Records

  • 0
  • 1
  • Question
  • Updated 4 years ago
  • Answered
Is there any way to disable the ability to delete a Master record if it has Child records?

I'm trying to prevent having orphaned child records.

I'v looked at Form Rules using - creating a rule based on a "# of Child records" summary field on the Master table edit form - I was trying to figure out if I can create a form rule which prevents the deletion of the Master record unless the value of the "# of Child records" summary field = 0 - but I have not been able to work out how to do this.

Thanks,

Ross
Photo of Ross

Ross

  • 0 Points

Posted 6 years ago

  • 0
  • 1
Photo of Eric

Eric

  • 40 Points
Currently there is no way to restrict a record from being deleted in QuickBase. If you would like to provide this as product feedback to our product development team we encourage you to do so here: http://quickbase.uservoice.com.
Photo of Harrison Hersch (MCF)

Harrison Hersch (MCF), Champion

  • 40 Points
Not sure if it helps, but you could dynamically restrict access to edit based on this criteria.
Photo of Harrison Hersch (MCF)

Harrison Hersch (MCF), Champion

  • 40 Points
One thing you could do would be disable permissions for the users in question to delete and place a magic button on the form that runs API Purge Record. In order to account for permissions, you would need to have it call a small PHP page with credentials in it with the elevated permissions. You could control things inside of this formula.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,434 Points 20k badge 2x thumb
You can redefine the function DoDelete() so it does not delete the record under specific conditions:

DoDelete= (function(fn){
return function(){
var result;
if (your condition here) {
//delete the record
result=fn.apply(fn, arguments);
} else {
//don't delete the record
result = null;
alert("I have grown attached to this record and I can not let you delete it.");
}
return result;
}
})(DoDelete);
Photo of Hing

Hing

  • 0 Points
Where do I find the DoDelete function?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,434 Points 20k badge 2x thumb
DoDelete() is a function QuickBase has authored. The code I wrote takes the original DoDelete() function that QuickBase authored and redefines it in a manner in which the user supplied condition (ie the "your condition here" part) will be tested before the original DoDelete() function is executed. It may seem odd to do it this way but it is in fact an extremely clever technique that you can use because JavaScipt allows functions to be manipulated and passed around in the same manner strings and number can be. So rather than tracking down DoDelete() and rewriting it we just modify if to do our bidding and the modified DoDelete() will be call wherever the original DoDelete() is called - when you attempt to delete a record.
Photo of Juan

Juan

  • 20 Points
dandiebolt: where would you insert this code so it runs whenever a user attempts to delete something?  Thanks in advance.
Photo of ITRx Beta

ITRx Beta

  • 0 Points
Was there ever an answer on where to insert this function? I am running into a similar issue to which I think this function may help.