Object Rule Manager (.NET)

You can use object rules to further customize the behavior of the object types that you create. The Object Rule Manager service simplifies this process by supporting CRUD operations on object rules. It also provides helper methods for retrieving information about associative objects, layouts, choices and choice fields used when creating or updating an object rule.

You can also use the Object Rule Manager and other related services through the REST API. For more information, see Object Rule Manager (REST).

This page contains the following information:

The Relativity.DataVisualization.SDK contains this API. For compatibility and package installation instructions, see Download the SDKs and NuGet packages.

Fundamentals for managing object rules

Click the following drop-down links to learn about the methods and classes used by the Object Rule Manager.

Guidelines for the Object Rule Manager API

Review the following guidelines for the Object Rule Manager service:

  • Use the Object Rule Manager service to work with the same object rule types available through the Relativity UI. For general information about object rules, see Adding an object rule.
  • Use the helper methods to retrieve information that you need when creating or updating an object rule. See the following table for suggested uses.
    Create or update this object rule Use these helper methodsCompares to this UI field

    Choice Behavior

    Choice field methodsField

    Default Layout

    Layout methodsAction
    Choice field methodsField
    Choice methodValue

    Default Layout on New

    Layout methodsAction

    Sub-List Button Visibility

    Choice field methodsField
    Choice methodValue
    Associated object methodsAssociative/Child Object
  • If a call to a helper method returns an empty list, you can't create that object rule on that object type.
  • To attach an object rule, the object type must be an RDO and non-system object, or a document object type.
  • Use -1 for the workspace ID when you want to indicate the admin-level context.
  • To retrieve the Artifact ID of an object rule, use the Object Manager Service. For more information, see Object Manager (.NET).

Create an object rule

You can create object rules by using the methods available on the IObjectRuleManager interface. For general information about object rules, see Adding an object rule.

Click the following drop-down links to view sample code for sub-list visibility, choices, and layouts rules. For more information about create methods, see the IObjectRuleManager interface in the Relativity.DataVisualization.{versionNumber}.ObjectRules namespace.

Read an object rule

You can retrieve basic information about an object rule or extended information, which also includes operations that you have permissions to perform on the object rule. If you want to return extended information, use the overloaded method by passing Boolean values set to true for additional metadata and permissions as follows:

ObjectRuleResponse response = await objectRuleManager.ReadAsync(workspaceId, objectRuleArtifactId, true, true);

The following code sample illustrates how to call the ReadAsync() method by passing only the Artifact IDs of the workspace and the object rule. Consequently, it returns only basic information.

public static async Task Read_Async()
{
    int workspaceId = 1018486;
    int objectRuleArtifactId = 1039509;
 
    using (Relativity.DataVisualization.{versionNumber}.ObjectRules.IObjectRuleManager objectRuleManager = serviceFactory.CreateProxy<Relativity.DataVisualization.{versionNumber}.ObjectRules.IObjectRuleManager>())
    {
        try
        {
            ObjectRuleResponse response = await objectRuleManager.ReadAsync(workspaceId, objectRuleArtifactId);
            string info = string.Format("Read object rule {0} with Artifact ID {1}", response.Name, response.ArtifactId);
            Console.Write(info);
        }
        catch (Exception ex)
        {
            Console.WriteLine(string.Format("An error occurred: {0}", ex.Message));
        }
    }       
}

Update an object rule

You can update object rules by using the methods available on the IObjectRuleManager interface. All object rules have an overloaded update method called by passing the Artifact IDs of a workspace and the object rule, the appropriate request object for the rule type, and an optional DateTime object.

Note: To get the Artifact ID of an object rule, use the ReadAsync() method on the Object Manager (.NET).

When you want to restrict the update of an object rule to the date that it was last modified, pass the value of LastModifiedOn property as an argument to one of the overloaded update methods. You can get the value of this property from an ObjectRuleResponse object, which is returned by the ReadAsync() method.

Click the following drop-down links to view sample code for sub-list visibility, choices, and layouts rules. For more information about update methods, see the IObjectRuleManager interface in the Relativity.DataVisualization.{versionNumber}.ObjectRules namespace.

Delete an object rule

You can remove an object rule from an object type by calling the DeleteAsync()method, and passing Artifact IDs of a workspace and an object rule to it. See the following code sample:

public static async Task Delete_Async()
{
    int workspaceId = 1018486;
    int objectRuleId = 1039509;
 
    using (Relativity.DataVisualization.{versionNumber}.ObjectRules.IObjectRuleManager objectRuleManager = serviceFactory.CreateProxy<Relativity.DataVisualization.{versionNumber}.ObjectRules.IObjectRuleManager>())
    {
        try
        {
            await objectRuleManager.DeleteAsync(workspaceId, objectRuleId);
        }
        catch (Exception ex)
        {
            Console.WriteLine(string.Format("An error occurred: {0}", ex.Message));
        }
    }
}

Delete multiple object rules

You can remove multiple object rules across different object types by making a single call to the MassDeleteAsync() method. Pass the Artifact ID of the workspace and a list containing the Artifact ID for each rule that you want to delete to this method. See the following code sample:

public static async Task Delete_Async()
{
    int workspaceId = 1018486;
    int objectRuleId1 = 1039509;
    int objectRuleId2 = 1039525;
    int objectRuleId3 = 1039630;
 
    List<ObjectIdentifiers> objectRulesToDelete = new List<ObjectIdentifiers> = [ objectRuleId1, objectRuleId2, objectRuleId3];
  
    using (Relativity.DataVisualization.{versionNumber}.ObjectRules.IObjectRuleManager objectRuleManager = serviceFactory.CreateProxy<Relativity.DataVisualization.{versionNumber}.ObjectRules.IObjectRuleManager>())
    {
        try
        {
            await objectRuleManager.MassDeleteAsync(workspaceId, objectRulesToDelete);
        }
        catch (Exception ex)
        {
            Console.WriteLine(string.Format("An error occurred: {0}", ex.Message));
        }
    }
}

Retrieve choices, choice fields, layouts, or associated objects

When you create or update an object rule, you must provide the Artifact ID of any associative objects, layouts, choices and choice fields that it references. The Object Rule Manager service provides several helper methods that you can use to retrieve the Artifact ID, name, and other information about these objects. For most objects, it includes overloaded methods with following signatures:

  • Method signature with workspace ID and Artifact ID parameters - use this method if you have the Artifact ID of the object type.
  • Method signature with workspace ID and DisplayableObjectTypeIdentifier object parameters - use this method if you have the user-friendly name of the object type, but not its Artifact ID.

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.