IBM FileNet P8, Version 5.2.1            

Working with Documents

The following code examples demonstrate document-related operations. Other document-related tasks are as follows:

Creating a Document

This example creates a document and optionally sets the properties MimeType, DocumentTitle, and StorageArea.

Java™ Example

// Create a document instance.
Document doc = Factory.Document.createInstance(os, ClassNames.DOCUMENT);

// Set document properties.
doc.getProperties().putValue("DocumentTitle", "New Document via Java API");
doc.set_MimeType("text/plain");

StorageArea sa = Factory.StorageArea.getInstance(os, new Id("{DE42374D-B04B-4F47-A62E-CAC9AC9A5719}") );
doc.set_StorageArea(sa);

doc.save(RefreshMode.NO_REFRESH );

// Check in the document.
doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
doc.save(RefreshMode.NO_REFRESH);

// File the document.
Folder folder = Factory.Folder.getInstance(os, ClassNames.FOLDER,
        new Id("{42A3FC29-D635-4C37-8C86-84BAC73FFA3F}") );
ReferentialContainmentRelationship rcr = folder.file(doc,
        AutoUniqueName.AUTO_UNIQUE, "New Document via Java API",
        DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
rcr.save(RefreshMode.NO_REFRESH);

C# Example

// Create a document instance.
IDocument doc = Factory.Document.CreateInstance(os, ClassNames.DOCUMENT);

// Set document properties.
doc.Properties["DocumentTitle"] = "New Document via .NET API";
doc.MimeType = "text/plain";

IStorageArea sa = Factory.StorageArea.GetInstance(os, new Id("{DE42374D-B04B-4F47-A62E-CAC9AC9A5719}"));
doc.StorageArea = sa;

doc.Save(RefreshMode.NO_REFRESH);

// Check in the document.
doc.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
doc.Save(RefreshMode.NO_REFRESH);

// File the document in a folder.
IFolder folder = Factory.Folder.GetInstance(os, ClassNames.FOLDER,
        new Id("{42A3FC29-D635-4C37-8C86-84BAC73FFA3F}"));
IReferentialContainmentRelationship rcr = folder.File(doc,
        AutoUniqueName.AUTO_UNIQUE, "New Document via .NET API",
        DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
rcr.Save(RefreshMode.NO_REFRESH);

Taking Federated Ownership

This example shows how to retrieve a document and take federated ownership.

Java Example

Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{F4DD983C-B845-4255-AC7A-257202B557EC}") );
doc.takeFederatedOwnership();
doc.save(RefreshMode.NO_REFRESH);

C# Example

IDocument doc = Factory.Document.GetInstance(os, ClassNames.DOCUMENT, new Id("{9E285404-1A8F-4828-AC2E-00ADD9BB3CB5}"));
doc.TakeFederatedOwnership();
doc.Save(RefreshMode.NO_REFRESH);

Retrieving a Document (getInstance)

This example retrieves a document by using the getInstance method and returns some properties. The getInstance method does not populate the property cache; if you want to work with properties, you must call the fetchProperties method.

Java Example

// Get document and populate property cache.
PropertyFilter pf = new PropertyFilter();
pf.addIncludeProperty(new FilterElement(null, null, null, "DocumentTitle", null) );
pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.MIME_TYPE, null) );
Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{F4DD983C-B845-4255-AC7A-257202B557EC}") );

// Fetch selected properties from the server.
doc.fetchProperties(pf);

// Return document properties.
com.filenet.api.property.Properties props = doc.getProperties();

// Iterate the set and print property values.
Iterator iter = props.iterator();
System.out.println("Property" +"\t" + "Value");
System.out.println("------------------------");
while (iter.hasNext() )
{
    Property prop = (Property)iter.next();
    if (prop.getPropertyName().equals("DocumentTitle") )
      System.out.println(prop.getPropertyName() + "\t" + prop.getStringValue() );
    else if (prop.getPropertyName().equals(PropertyNames.MIME_TYPE,) )
      System.out.println(prop.getPropertyName() + "\t" + prop.getStringValue() );
}

C# Example

// Get document and populate property cache.
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(new FilterElement(null, null, null, "DocumentTitle", null));
pf.AddIncludeProperty(new FilterElement(null, null, null, PropertyNames.MIME_TYPE, null));
IDocument doc = Factory.Document.GetInstance(os, ClassNames.DOCUMENT, new Id("{9E285404-1A8F-4828-AC2E-00ADD9BB3CB5}") );

// Fetch selected properties from the server
doc.FetchProperties(pf);

// Return document properties.
IProperties props = doc.Properties;

// Iterate the set and print property values.
System.Collections.IEnumerator propsIter = props.GetEnumerator();
System.Console.WriteLine("Property" +"\t" + "Value");
System.Console.WriteLine("------------------------");
while (propsIter.MoveNext())
{
    IProperty prop = (IProperty)propsIter.Current;
    if (prop.GetPropertyName().Equals("DocumentTitle") )
        System.Console.WriteLine(prop.GetPropertyName() + "\t" + prop.GetStringValue() );
    else if (prop.GetPropertyName().Equals(PropertyNames.MIME_TYPE) )
        System.Console.WriteLine(prop.GetPropertyName() + "\t" + prop.GetStringValue() ); 
}

Retrieving a Document (fetchInstance)

This example retrieves a document by using the fetchInstance method and returns some properties. The fetchInstance method populates the property cache with the specified properties.

Java Example

// Get document and populate property cache.
PropertyFilter pf = new PropertyFilter();    
pf.addIncludeProperty(new FilterElement(null, null, null, "DocumentTitle", null) );
pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.MIME_TYPE, null) );
Document doc = Factory.Document.fetchInstance(os, new Id("{F4DD983C-B845-4255-AC7A-257202B557EC}"),pf );

// Return document properties.
com.filenet.api.property.Properties props = doc.getProperties();

// Iterate the set and print property values. 
Iterator iter = props.iterator();
System.out.println("Property" +"\t" + "Value");
System.out.println("------------------------");
while (iter.hasNext() )
{
    Property prop = (Property)iter.next();
    if (prop.getPropertyName().equals("DocumentTitle") )
        System.out.println(prop.getPropertyName() + "\t" + prop.getStringValue() );
    else if (prop.getPropertyName().equals(PropertyNames.MIME_TYPE) )
        System.out.println(prop.getPropertyName() + "\t" + prop.getStringValue() );
}

C# Example

//  Get document and populate property cache.
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(new FilterElement(null, null, null, "DocumentTitle", null));
pf.AddIncludeProperty(new FilterElement(null, null, null, PropertyNames.MIME_TYPE, null));
IDocument doc = Factory.Document.FetchInstance(os, new Id("{9E285404-1A8F-4828-AC2E-00ADD9BB3CB5}"), pf);

// Return document properties.
IProperties props = doc.Properties;

// Iterate the set and print property values.
System.Collections.IEnumerator propsIter = props.GetEnumerator();
System.Console.WriteLine("Property" +"\t" + "Value");
System.Console.WriteLine("------------------------");
while (propsIter.MoveNext())
{
    IProperty prop = (IProperty)propsIter.Current;
    if (prop.GetPropertyName().Equals("DocumentTitle") )
        System.Console.WriteLine(prop.GetPropertyName() + "\t" + prop.GetStringValue() );
    else if (prop.GetPropertyName().Equals(PropertyNames.MIME_TYPE) )
        System.Console.WriteLine(prop.GetPropertyName() + "\t" + prop.GetStringValue() );
}

Deleting a Document

This example deletes a document. Deleting a document deletes, in addition to the document object itself, any associated internal content, annotations, and possibly other dependent objects. Delete operations entirely fail or succeed. For example, not having the required permissions to delete any of the document's versions or dependent objects (for example, an annotation) causes the entire delete operation to fail. You can prevent document deletions in the following ways: security permissions, restrictions that are imposed by compound document relationships, and by using the storage area AllowsDelete and RetentionPeriod properties.

Java Example

Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{A26C3EF4-7C02-4D01-84CD-D3D7F1D5DA19}") );
doc.delete();
doc.save(RefreshMode.NO_REFRESH);

C# Example

IDocument doc = Factory.Document.GetInstance(os, ClassNames.DOCUMENT, new Id("{6B3E6E63-23B1-4D29-8E91-8632E30F10C5}"));
doc.Delete();
doc.Save(RefreshMode.NO_REFRESH);

Updating Document Properties

This example retrieves the DocumentTitle property, changes its value, and refreshes the property cache.

Java Example

// Get document and populate property cache.
PropertyFilter pf = new PropertyFilter();
pf.addIncludeProperty(new FilterElement(null, null, null, "DocumentTitle", null));
Document doc = Factory.Document.fetchInstance(os, new Id("{F4DD983C-B845-4255-AC7A-257202B557EC}"),pf );

// Return document properties.
com.filenet.api.property.Properties props = doc.getProperties();

// Change property value.
props.putValue("DocumentTitle", "Document with Updated Title via Java API");

// Save and update property cache.
doc.save(RefreshMode.REFRESH );

C# Example

// Get document and populate property cache.
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(new FilterElement(null, null, null, "DocumentTitle", null));
IDocument doc = Factory.Document.FetchInstance(os, new Id("{9E285404-1A8F-4828-AC2E-00ADD9BB3CB5}"), pf);

// Return document properties.
IProperties props = doc.Properties;

// Change property value.
doc.Properties["DocumentTitle"] = "Document with Updated Title via .NET API";

// Save and update property cache.
doc.Save(RefreshMode.REFRESH);

Setting a Document's Content

This example sets a document's content

Java Example

// Get document.
Document doc=Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{8FD91CF0-E991-426D-9BCB-B63F0E30E604}") );

// Check out the Document object and save it.
doc.checkout(com.filenet.api.constants.ReservationType.EXCLUSIVE, null, doc.getClassName(), doc.getProperties());
doc.save(RefreshMode.REFRESH);

// Get the Reservation object from the Document object.
Document reservation = (Document) doc.get_Reservation();

// Specify internal and external files to be added as content.
File internalFile = new File("C:\\docs\mydoc.txt");
// non-Windows: File internalFile = new File("/tmp/docs/mydoc.txt");
String externalFile = "ftp://ftp.mycompany.com/docs/relnotes.txt";

// Add content to the Reservation object.
try {
    // First, add a ContentTransfer object.
    ContentTransfer ctObject = Factory.ContentTransfer.createInstance();
    FileInputStream fileIS = new FileInputStream(internalFile.getAbsolutePath());
    ContentElementList contentList = Factory.ContentTransfer.createList();
    ctObject.setCaptureSource(fileIS);
    // Add ContentTransfer object to list.
    contentList.add(ctObject);

    // Second, add a ContentReference object.
    ContentReference crObject = Factory.ContentReference.createInstance(os);
    crObject.set_ContentLocation(externalFile);
    crObject.set_ContentType("text/plain"); // Must be set for ContentReference.
    // Add ContentReference object to list.
    contentList.add(crObject);

    reservation.set_ContentElements(contentList);
    reservation.save(RefreshMode.REFRESH);
    }
catch (Exception e)
{
    System.out.println(e.getMessage() );
}

// Check in Reservation object as major version.
reservation.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
reservation.save(RefreshMode.REFRESH);

C# Example

// Get document.
IDocument doc=Factory.Document.GetInstance(os, ClassNames.DOCUMENT, new Id("{9E285404-1A8F-4828-AC2E-00ADD9BB3CB5}") );

// Check out the Document object and save it.
doc.Checkout(ReservationType.EXCLUSIVE, null, doc.GetClassName(), doc.Properties);
doc.Save(RefreshMode.REFRESH);

// Get the Reservation object from the Document object.
IDocument reservation = (IDocument) doc.Reservation;

// Specify internal and external files to be added as content.
Stream internalFile = File.OpenRead(@"C:\\BootstrapConfigUtility.bat");
String externalFile = "file://C:\\BootstrapConfigUtility.bat";

// Add content to the Reservation object.
try {
    // First, add a ContentTransfer object.
    IContentTransfer ctObject = Factory.ContentTransfer.CreateInstance();
    IContentElementList contentList = Factory.ContentTransfer.CreateList();
    ctObject.SetCaptureSource(internalFile);
    // Add ContentTransfer object to list.
    contentList.Add(ctObject);

    // Second, add a ContentReference object.
    IContentReference crObject = Factory.ContentReference.CreateInstance(os);
    crObject.ContentLocation = externalFile;
    crObject.ContentType = "text/plain";// Must be set for ContentReference.
    // Add ContentReference object to list.
    contentList.Add(crObject);

    reservation.ContentElements = contentList;
    reservation.Save(RefreshMode.REFRESH);
}
catch (Exception e)
{
    System.Console.WriteLine(e.Message);
}

// Check in Reservation object as major version.
reservation.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
reservation.Save(RefreshMode.REFRESH);

Retrieving a Document's Content

This example displays information about a document's content and prints the content. First, it prints document properties about its content: the number of content elements in the document, and the document's size, which is the total of all of the content elements. Second, it retrieves the document's content element list. For each content element, it prints some property values and then the content itself.

Java Example

// Get document and populate property cache.
PropertyFilter pf = new PropertyFilter();
pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.CONTENT_SIZE, null) );
pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.CONTENT_ELEMENTS, null) );
Document doc=Factory.Document.fetchInstance(os, "{9FEC3C69-57B2-4E29-872A-0EE452881555}", pf );

// Print information about content elements.
System.out.println("No. of document content elements: " + doc.get_ContentElements().size() + "\n" +
 "Total size of content: " + doc.get_ContentSize() + "\n");

// Get content elements and iterate list.
ContentElementList docContentList = doc.get_ContentElements();
Iterator iter = docContentList.iterator();
while (iter.hasNext() )
{
    ContentTransfer ct = (ContentTransfer) iter.next();

    // Print element sequence number and content type of the element.
    System.out.println("\nElement Sequence number: " + ct.get_ElementSequenceNumber().intValue() + "\n" +
     "Content type: " + ct.get_ContentType() + "\n");

    // Get and print the content of the element.
    InputStream stream = ct.accessContentStream();
    String readStr = "";
    try
    {
        int docLen = 1024;
        byte[] buf = new byte[docLen];
        int n = 1;
        while (n > 0)
        {
           n =  stream.read(buf, 0, docLen);
           readStr = readStr + new String(buf);
           buf = new byte[docLen];
        }
        System.out.println("Content:\n " + readStr);
        stream.close();
    }
    catch(IOException ioe)
    {
        ioe.printStackTrace();
    }
}

C# Example

// Get document and populate property cache.
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(new FilterElement(null, null, null, PropertyNames.CONTENT_SIZE, null));
pf.AddIncludeProperty(new FilterElement(null, null, null, PropertyNames.CONTENT_ELEMENTS, null));
IDocument doc = Factory.Document.FetchInstance(os, "{9FEC3C69-57B2-4E29-872A-0EE452881555}", pf);

// Print information about content elements.
System.Console.WriteLine("No. of document content elements: " + doc.ContentElements.Count + "\n" +
 "Total size of content: " + doc.ContentSize + "\n");

// Get content elements and iterate list.
IContentElementList docContentList = doc.ContentElements;
System.Collections.IEnumerator iter = docContentList.GetEnumerator();
while (iter.MoveNext())
{
    IContentTransfer ct = (IContentTransfer)iter.Current;

    // Print element sequence number and content type of the element.
    System.Console.WriteLine("\nElement Sequence number: " + ct.ElementSequenceNumber.Value + "\n" +
     "Content type: " + ct.ContentType + "\n");

    // Get and print the content of the element.
    String readStr = "";
    try
    {
        Stream stream = ct.AccessContentStream();
        int docLen = 1024;
        byte[] buf = new byte[docLen];
        int n = 1;
        while (n > 0)
        {
            n = stream.Read(buf, 0, docLen);
            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
            StringBuilder sb = new StringBuilder();
            sb.Append(enc.GetString(buf), 0, docLen);
            readStr=sb.ToString();
            buf = new byte[docLen];
        }
        System.Console.WriteLine("Content:\n " + readStr);
        stream.Close();
    }
    catch(IOException ioe)
    {
        System.Console.WriteLine(ioe.Message);
    }
}

Assigning a Storage Area

A storage area is only settable when a document is created. See Creating a Document.

Assigning a Storage Policy

The following example assigns a storage policy to a document. The code can be effective only if the storage area associated with the policy is closed or full. The new policy takes effect when the document is next checked out and then checked in.

Java Example

// Get document and populate property cache.
PropertyFilter pf = new PropertyFilter();
pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.STORAGE_POLICY, null));
Document doc=Factory.Document.fetchInstance(os, "{33074B6E-FD19-4C0D-96FC-D809633D35BE}", pf );

// Print name of current storage policy.
System.out.println("Current storage policy: " + doc.get_StoragePolicy().get_DisplayName() );

// Set new storage policy and print name.
StoragePolicy sp = Factory.StoragePolicy.getInstance(os, new Id("{BA065E85-7D01-48E3-9266-4EFDC8D8FAE3}") );
doc.set_StoragePolicy(sp);
doc.save(RefreshMode.REFRESH);
System.out.println("New storage policy: " + doc.get_StoragePolicy().get_DisplayName() );

C# Example

// Get document and populate property cache.
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(new FilterElement(null, null, null, PropertyNames.STORAGE_POLICY, null));
IDocument doc=Factory.Document.FetchInstance(os, "{61BA91F0-6639-4A12-A784-CD274AADF9AA}", pf );

// Print name of current storage policy.
System.Console.WriteLine("Current storage policy: " + doc.StoragePolicy.DisplayName);

// Set new storage policy and print name.
IStoragePolicy sp = Factory.StoragePolicy.GetInstance(os, new Id("{BA065E85-7D01-48E3-9266-4EFDC8D8FAE3}") );
doc.StoragePolicy = sp;
doc.Save(RefreshMode.REFRESH);
System.Console.WriteLine("New storage policy: " + doc.StoragePolicy.DisplayName);

Moving a Document's Content

These examples illustrate how to move a document's content to a different storage area. The second example illustrates moving the content of a document after the document's class is changed.

The following example moves a document's content to a different storage area. In this case, the content is moved to a database storage area.

Java Example

// Get the storage area where you want to move the document content.
DatabaseStorageArea dsa = Factory.DatabaseStorageArea.fetchInstance(os, new Id("{3C6CEE68-D8CC-44A5-AEE7-CADE9752AA75}"), null );

// Get the Document object whose content you want to move.
Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{33074B6E-FD19-4C0D-96FC-D809633D35BE}") );

// Move the content and save the Document object.
doc.moveContent(dsa);
doc.save(RefreshMode.REFRESH);

C# Example

// Get the storage area where you want to move the document content.
IDatabaseStorageArea dsa = Factory.DatabaseStorageArea.FetchInstance(os, new Id("{3C6CEE68-D8CC-44A5-AEE7-CADE9752AA75}"), null);

// Get the Document object whose content you want to move.
IDocument doc = Factory.Document.GetInstance(os, ClassNames.DOCUMENT, new Id("{61BA91F0-6639-4A12-A784-CD274AADF9AA}"));

// Move the content and save the Document object.
doc.MoveContent(dsa);
doc.Save(RefreshMode.REFRESH);

The following example changes a document’s class and also moves the document's content to a storage area associated with the new document class. In this case, the content is moved to a file storage area.

Java Example

// Get the storage area associated with the new document class.
FileStorageArea newDocClassFSA = Factory.FileStorageArea.fetchInstance(os, new Id("{3C6CEE68-D8CC-44A5-AEE7-CADE9752AA77}"), null );

// Get the Document object whose content you want to move.
Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{33074B6E-FD19-4C0D-96FC-D809633D35BE}") );

// Get the Document object whose class you want to change
// and whose content you want to move.
Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{33074B6E-FD19-4C0D-96FC-D809633D35BF}") );

// Change the document class.
doc.changeClass(“newDocClass”);

// Move the content to the storage area associated with the new document class
// and save the Document object.
doc.moveContent(newDocClassFSA);
doc.save(RefreshMode.REFRESH);

C# Example

// Get the storage area associated with the new document class.
IFileStorageArea newDocClassFSA = Factory.FileStorageArea.FetchInstance(os, new Id("{3C6CEE68-D8CC-44A5-AEE7-CADE9752AA77}"), null);
 
// Get the Document object whose class you want to change
// and whose content you want to move.
IDocument doc = Factory.Document.GetInstance(os, ClassNames.DOCUMENT, new Id("{61BA91F0-6639-4A12-A784-CD274AADF9AB}"));
 
// Change the document class.
doc.ChangeClass("newDocClass");

// Move the content to the storage area associated with the new document class
// and save the Document object.
doc.MoveContent(newDocClassFSA);
doc.Save(RefreshMode.REFRESH);

Unfiling a Document

This example shows one way of unfiling a document from a folder that contains it. For the example to work, it requires a reference to the document to be unfiled.

A document is connected to a containing folder by a ReferentialContainmentRelationship (RCR) object. The RCR's Head property points to the document, and the RCR's Tail property points to the containing folder. Because a document can be referenced by multiple folders, the example gets a set of RCR objects from the document, and iterates the set to find the RCR object with the Tail property that matches the folder of interest. When the RCR object is found, it is deleted.

Java Example

static PropertyFilter pf = new PropertyFilter(); 

pf.addIncludeProperty(new FilterElement(null, null, null, "Containers", null));
// Get document to be unfiled.
Document doc = Factory.Document.fetchInstance(os, new Id("{8854236F-02D6-40AB-B4B2-59B6756154D8}"), pf);

// Iterate all folders that contain the document, until the desired folder is found.
ReferentialContainmentRelationshipSet rcrs = doc.get_Containers();
Iterator iter = rcrs.iterator();
while (iter.hasNext() )
{
   ReferentialContainmentRelationship rcr = (ReferentialContainmentRelationship)iter.next();
   Folder folder = (Folder)rcr.get_Tail();
   if (folder.get_Id().equals(new Id("{C40106FE-B510-4222-BB42-6D2FD5D21123}")))
   {
      rcr.delete();
      rcr.save(RefreshMode.REFRESH);
      break;
   }
}

C# Example

static PropertyFilter pf = new PropertyFilter();

pf.AddIncludeProperty(new FilterElement(null, null, null, "Containers", null));
// Get document to be unfiled.
IDocument doc = Factory.Document.FetchInstance(os, new Id("{8854236F-02D6-40AB-B4B2-59B6756154D8}"), pf);

// Iterate all folders that contain the document, until the desired folder is found.
IReferentialContainmentRelationshipSet rcrs = doc.Containers;
foreach (IReferentialContainmentRelationship rcr in rcrs)
{
   IFolder folder = (IFolder)rcr.Tail;
   if (folder.Id.Equals(new Id("{C40106FE-B510-4222-BB42-6D2FD5D21123}")))
   {
      rcr.Delete();
      rcr.Save(RefreshMode.REFRESH);
      break;
   }
}

Customizing a Document Class

This example customizes the Email class by adding a new property (eMail signature) to the class. A LocalizedString object is required for the name and descriptive text, which is returned by a getLocalizedString method.

Java Example

public void customizeClass()
{
    //  Fetch selected class definition from the server.
    ClassDefinition classDef = Factory.ClassDefinition.fetchInstance(os, "Email", null );

    // Create new PropertyTemplate for object property with optional value.
    PropertyTemplateObject newPropTemplate = Factory.PropertyTemplateObject.createInstance(os);
    newPropTemplate.set_Cardinality (Cardinality.SINGLE);
    newPropTemplate.set_IsValueRequired(Boolean.FALSE);

    // Set required properties to locale-specific string.
    LocalizedString locStr1 = getLocalizedString("eMail Signature", os.get_LocaleName() );
    // Create LocalizedString collection.
    newPropTemplate.set_DisplayNames (Factory.LocalizedString.createList() );
    newPropTemplate.get_DisplayNames().add(locStr1);

    LocalizedString locStr2 = getLocalizedString("Signature of sender",
       os.get_LocaleName() );
    newPropTemplate.set_DescriptiveTexts(Factory.LocalizedString.createList() );
    newPropTemplate.get_DescriptiveTexts().add(locStr2);

    // Save property template to the server.
    newPropTemplate.save(RefreshMode.REFRESH);

    // Create property definition from property template.
    PropertyDefinitionObject newPropDef = (PropertyDefinitionObject)newPropTemplate.createClassProperty();

    // Set RequiredClass property to Email Items.
    newPropDef.set_RequiredClassId(new Id("{BFA64F40-5C45-45B1-B540-B5BA3CA08AAB}") );

    // Get PropertyDefinitions property from the property cache.
    PropertyDefinitionList propDefs = classDef.get_PropertyDefinitions();

    // Add new property definition to class definition.
    propDefs.add(newPropDef);

    classDef.save(RefreshMode.REFRESH);
}

private LocalizedString getLocalizedString(String text, String locale)
{
    LocalizedString locStr = Factory.LocalizedString.createInstance ();
    locStr.set_LocalizedText(text);
    locStr.set_LocaleName (locale);
    return locStr;
}

C# Example

public void customizeClass()
{
    // Fetch selected class definition from the server.
    IClassDefinition classDef = Factory.ClassDefinition.FetchInstance(os, "Email", null);

    // Create new PropertyTemplate for object property with optional value.
    IPropertyTemplateObject newPropTemplate = Factory.PropertyTemplateObject.CreateInstance(os);
    newPropTemplate.Cardinality = Cardinality.SINGLE;
    newPropTemplate.IsValueRequired = false;

    // Set required properties to locale-specific string.
    ILocalizedString locStr1 = getLocalizedString("eMail Signature", os.LocaleName);
    // Create LocalizedString collection
    newPropTemplate.DisplayNames = Factory.LocalizedString.CreateList();
    newPropTemplate.DisplayNames.Add(locStr1);

    ILocalizedString locStr2 = getLocalizedString("Signature of sender", os.LocaleName);
    newPropTemplate.DescriptiveTexts = Factory.LocalizedString.CreateList();
    newPropTemplate.DescriptiveTexts.Add(locStr2);

    // Save property template to the server.
    newPropTemplate.Save(RefreshMode.REFRESH);

    // Create property definition from property template.
    IPropertyDefinitionObject newPropDef = (IPropertyDefinitionObject)newPropTemplate.CreateClassProperty();

    // Set RequiredClass property to Email Items.
    newPropDef.RequiredClassId = new Id("{BFA64F40-5C45-45B1-B540-B5BA3CA08AAB}");

    // Get PropertyDefinitions property from the property cache.
    IPropertyDefinitionList propDefs = classDef.PropertyDefinitions;

    // Add new property definition to class definition.
    propDefs.Add(newPropDef);

    classDef.Save(RefreshMode.REFRESH);
}

private ILocalizedString getLocalizedString(String text, String locale)
{
    ILocalizedString locStr = Factory.LocalizedString.CreateInstance();
    locStr.LocalizedText = text;
    locStr.LocaleName = locale;
    return locStr;
}


Last updated: October 2015
document_procedures.htm

© Copyright IBM Corporation 2015.