Pre Cascade Delete event handlers

You call a Pre Cascade Delete event handler when a user attempts to force the deletion of an object with dependent objects. The user must have Delete Object Dependencies permissions to perform this action.

You can use this type of event handler to verify that no restrictions exist on an object selected for deletion. For example, the Processing Set Pre Cascade Delete event handler prevents the deletion of a processing set while it is undergoing processing.

In a forced delete operation, the Pre Cascade Delete event runs before Relativity begins deleting child objects or unlinking associative objects. After completing these operations, Relativity deletes the parent object. The Pre Cascade Delete event handler ensures that the system initiates a forced delete operation only when it can successfully remove the objects.

Note: To view the items for deletion, use the TempTableNameWithParentArtifactsToDelete string property of the PreCascadeDeleteEventHandler base class. It holds the name of the scratch table that contains the ArtifactIDs marked for deletion.

We recommend using a Pre Delete event handler in conjunction with Pre Cascade Delete event handler. The Pre Cascade Delete event handler won't run when no associated or child objects exist. For more information, see Pre Delete event handlers.

This page contains the following information:

Guidelines for Pre Cascade Delete event handlers

  • Create a new class in Visual Studio.

    Note: You can also use a template to create this event handler type. For more information, see Visual Studio templates.

  • Add NuGet packages - ensure your Visual Studio project has installed the relevant NuGet packages, including at a minimum the Relativity.EventHandler and Relativity.Api packages.
  • Add a GUID for the event handler - set the System.Runtime.InteropServices.Guid to the GUID identifying your event handler. Use the GUID generator in Visual Studio.
  • Set the CustomAttributes.Description attribute - provide a description that you want to appear in the Relativity UI for the event handler.
  • Inherit from the PreCascadeDeleteEventHandler class – extend the PreCascadeDeleteEventHandler base class.
  • Override the RequiredFields property – you must override this property even though a Pre Cascade Delete event handler doesn't use it.

Code sample for a Pre Cascade Delete event handler

Review the following code sample for a Pre Cascade Delete event handler.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using kCura.EventHandler;
 
namespace CustomEventHandler
{
     [kCura.EventHandler.CustomAttributes.Description("A description of the event handler.")]
     public class TaskPreCascadeDeleteEventHandeler :  PreCascadeDeleteEventHandler
     {
          public override Response Execute() {
               Response resp = new Response() {
                    Success = true,
                    Message = ""
               };
           
               try {
                    // Execute code for the specific event here.
                    // To prevent the cascade delete operation, the event handler must return an exception and set success = false.
                    // For example, resp.Success = false; resp.Exception = new SystemException(“Some exception message”);
               }
               catch (Exception e) {
                    resp.Success = false;
               resp.Exception = new SystemException("ProcessPreDeleteFailure failure: "
                    + e.Message);
               }
               return resp;
          }
          public override FieldCollection RequiredFields
          {
               // Add any required fields.
               // If none are required, you can initialize a new collection instead.
               get { return new FieldCollection(); }
          }
          public override void Commit()
          {
               // Commit is unused (never gets called) in a Pre Cascade Delete event.
                
          }
          public override void Rollback()
          {
               // Code executes when an error occurs in the process.
                
               // If you're retrieving information that requires a rollback in Execute() method, then handle this operation here. Otherwise, leave this method blank.
          }
     }
}
            

Additional Resources

DevHelp Community GitHub Release Notes NuGet

Share knowledge with the Relativity developer community.

Access tools and resources to build an application.

Review the most recent product release notes.

Create .NET Apps faster with NuGet.