The following code examples demonstrate hold-related operations.
For an overview of hold functions, see Holds.
The following Java™ and C# examples create an instance from a subclass of CmHold. The subclass includes a custom property, which associates the hold with a case number.
Java Example
// Create instance from CmHold subclass, HoldForDepositions.
CmHold hold = Factory.CmHold.createInstance(os, "HoldForDepositions");
// Set system properties.
hold.set_DisplayName("Legal Hold for Depositions");
hold.set_DescriptiveText("Release subject to approval by case manager.");
// Set custom property.
hold.getProperties().putValue("CaseNumber", 1827749);
// Save hold instance to the server.
hold.save(RefreshMode.REFRESH);
C# Example
// Create instance from CmHold subclass, HoldForDepositions.
ICmHold hold = Factory.CmHold.CreateInstance(os, "HoldForDepositions");
// Set system properties.
hold.DisplayName="Legal Hold for Depositions";
hold.DescriptiveText="Release subject to approval by case manager.";
// Set custom property.
hold.Properties["LegalCaseNumber"]= 1827749;
// Save hold instance to the server.
hold.Save(RefreshMode.REFRESH);
The following Java and C# examples apply a hold to the document.
Java Example
// Get document to hold.
Document heldObject = Factory.Document.getInstance(os, ClassNames.DOCUMENT,
new Id("{FD973204-3106-4252-8F29-C5CBBAB98B19}"));
// Get hold object to apply to document.
CmHold hold = Factory.CmHold.getInstance(os, "HoldForDepositions", new Id("{DD2032CE-62D1-470D-91FD-10D818E2138A}"));
// Create CmHoldRelationship object.
CmHoldRelationship relationship = Factory.CmHoldRelationship.createInstance(os, ClassNames.CM_HOLD_RELATIONSHIP);
// Set Hold and HeldObject properties on CmHoldRelationship object.
relationship.set_Hold(hold);
relationship.set_HeldObject(heldObject);
// Save relationship to the server.
relationship.save(RefreshMode.REFRESH);
C# Example
// Get document to hold
IDocument heldObject = Factory.Document.GetInstance(os, ClassNames.DOCUMENT,
new Id("{FD973204-3106-4252-8F29-C5CBBAB98B19}"));
// Get hold object to apply to object
ICmHold hold = Factory.CmHold.GetInstance(os, "HoldForDepositions", new Id("{DD2032CE-62D1-470D-91FD-10D818E2138A}"));
// Create CmHoldRelationship object.
ICmHoldRelationship relationship = Factory.CmHoldRelationship.CreateInstance(os, ClassNames.CM_HOLD_RELATIONSHIP);
// Set Hold and HeldObject objects on CmHoldRelationship object.
relationship.Hold=hold;
relationship.HeldObject=heldObject;
// Save hold instance to the server.
relationship.Save(RefreshMode.REFRESH);
The following Java and C# examples list all of the CmHoldable objects to which the same hold applies.
Java Example
static PropertyFilter pf = new PropertyFilter();
...
// Get hold object.
pf.addIncludeProperty(new FilterElement(1, null, null, "CmHoldRelationships DisplayName HeldObject", null));
CmHold hold = Factory.CmHold.fetchInstance(os, new Id("{DD2032CE-62D1-470D-91FD-10D818E2138A}"), pf);
// Return relationship objects associated with the holds.
CmHoldRelationshipSet rsSet = hold.get_CmHoldRelationships();
// Iterate set and print name of each held object.
System.out.println(hold.get_DisplayName() + ":");
Iterator iter = rsSet.iterator();
while (iter.hasNext())
{
CmHoldRelationship relationship = (CmHoldRelationship) iter.next();
CmHoldable heldObject = relationship.get_HeldObject();
if (heldObject.getClass().getSimpleName().startsWith("Annot"))
{
System.out.println(" Annotation object: " + ((Annotation) heldObject).get_Name());
}
else System.out.println(" Containable object: " + ((Containable) heldObject).get_Name());
}
C# Example
static PropertyFilter pf = new PropertyFilter();
...
// Get hold object.
pf.AddIncludeProperty(new FilterElement(1, null, null, "CmHoldRelationships DisplayName HeldObject", null));
ICmHold hold = Factory.CmHold.FetchInstance(os, new Id("{DD2032CE-62D1-470D-91FD-10D818E2138A}"), pf);
// Return relationship objects associated with the holds.
ICmHoldRelationshipSet rsSet = hold.CmHoldRelationships;
// Iterate set and print name of each held object.
System.Console.WriteLine(hold.DisplayName + ":");
foreach (ICmHoldRelationship relationship in rsSet)
{
ICmHoldable heldObject = relationship.HeldObject;
if (heldObject.GetType().Name.StartsWith("Annot"))
{
System.Console.WriteLine(" Annotation object: " + ((IAnnotation) heldObject).Name);
}
else System.Console.WriteLine(" Containable object: " + ((IContainable) heldObject).Name);
}
The following Java and C# examples illustrate two ways of removing holds. First, the code removes a hold on a single document by deleting the applicable CmHoldRelationship object that references the target hold. Second, the code removes a hold on all objects to which the hold applies. It does that by deleting the target CmHold object.
Java Example
static PropertyFilter pf = new PropertyFilter();
...
// Remove hold on a single document.
// Get document to remove from hold.
pf.addIncludeProperty(new FilterElement(1, null, null, "CmHoldRelationships Hold", null));
Document heldObject = Factory.Document.fetchInstance(os,
new Id("{FD973204-3106-4252-8F29-C5CBBAB98B19}"), pf);
// Return relationship objects associated with the document.
CmHoldRelationshipSet rsSet = heldObject.get_CmHoldRelationships();
// Iterate set to find target hold to be removed.
Iterator iter = rsSet.iterator();
while (iter.hasNext())
{
CmHoldRelationship relationship = (CmHoldRelationship) iter.next();
CmHold holdObject = relationship.get_Hold();
if (holdObject.get_Id().equals(new Id("{1492D46F-D5CD-4CCA-9781-0F9E1B0D03E9})) )
{
relationship.delete();
relationship.save(RefreshMode.REFRESH);
System.out.println("Hold for Review removed from document");
}
}
///////////////////////////////////
// Remove hold on all objects to which the hold applies.
// Get hold object to delete.
CmHold hold = Factory.CmHold.getInstance(os, "HoldForDepositions", new Id("{DD2032CE-62D1-470D-91FD-10D818E2138A}"));
hold.delete();
hold.save(RefreshMode.REFRESH);
System.out.println("Legal Hold for Depositions removed from all CmHoldable objects");
C# Example
static PropertyFilter pf = new PropertyFilter();
...
// Remove hold on a single document.
// Get document to remove from hold.
pf.AddIncludeProperty(new FilterElement(1, null, null, "CmHoldRelationships Hold", null));
IDocument heldObject = Factory.Document.FetchInstance(os,
new Id("{FD973204-3106-4252-8F29-C5CBBAB98B19}"), pf);
// Return relationship objects associated with the document.
ICmHoldRelationshipSet rsSet = heldObject.CmHoldRelationships;
// Iterate set to find target hold to be removed.
foreach (ICmHoldRelationship relationship in rsSet)
{
ICmHold holdObject = relationship.Hold;
if (holdObject.Id.Equals(new Id("{1492D46F-D5CD-4CCA-9781-0F9E1B0D03E9}")))
{
relationship.Delete();
relationship.Save(RefreshMode.REFRESH);
System.Console.WriteLine("Hold for Review removed from document");
}
}
///////////////////////////////////
// Remove hold on all objects to which the hold applies.
// Get hold object to delete.
ICmHold hold = Factory.CmHold.GetInstance(os, ""HoldForDepositions"", new Id("{DD2032CE-62D1-470D-91FD-10D818E2138A}"));
hold.Delete();
hold.Save(RefreshMode.REFRESH);
System.Console.WriteLine("Legal Hold for Depositions removed from all CmHoldable objects");