Working with Choice Lists

Creating a Choice List

To create a choice list, follow these steps:

  1. Create a Choice object for each choice item that you want in the choice list by calling the Factory.Choice.createInstance method.
  2. For each Choice object:
    1. Set the ChoiceType property to determine the type of Choice object: integer, string, integer group node, or string group node:
      1. Integer: Set the ChoiceType property to ChoiceType.INTEGER. To set an integer value, use the ChoiceIntegerValue property.
      2. String: Set the ChoiceType property to ChoiceType.STRING. To set a string value, use the ChoiceStringValue property.
      3. Integer group node: Set the ChoiceType property to ChoiceType.MIDNODE_INTEGER. To set an integer-type ChoiceList object value, use the ChoiceValues property.
      4. String group node: Set the ChoiceType property to ChoiceType.MIDNODE_STRING. To set a string-type ChoiceList object value, use the ChoiceValues property.
    2. Set the DisplayNames property (if you are setting the DisplayName property instead, skip to step c):
      1. Call the Factory.LocalizedString.createInstance method to create a LocalizedString object.
      2. Set the LocalizedString object's LocaleName property to the value of the ObjectStore object's LocaleName property.
      3. Set the LocalizedString object's LocalizedText property to a string specifying the name of the choice item.
      4. Call the Factory.LocalizedString.createList method to create a LocalizedStringList collection object and set it to the Choice object's DisplayNames property.
      5. Call the DisplayNames property's add method to add the LocalizedString object to its LocalizedStringList collection.
      6. Proceed to step 3.
    3. Set the DisplayName property to a string specifying the name of the choice item.
  3. Create a ChoiceList list collection by calling Factory.Choice.createList and add the Choice objects that will belong to the choice list.
  4. Create a ChoiceList object by calling Factory.ChoiceList.createInstance.
  5. Set the ChoiceValues property of the ChoiceList object created in step 4 to a com.filenet.api.constants.ChoiceList object that contains the list collection of Choice objects that you created in step 3.

The following code example demonstrates how to create string and integer-type choice lists:

Java Example

/***************************
 * String-type choice list * 
 ***************************/
 
// Create string-type Choice objects for a group
Choice objChoiceMidStr1 = Factory.Choice.createInstance();
objChoiceMidStr1.set_ChoiceType(ChoiceType.STRING);
objChoiceMidStr1.set_DisplayName("Seattle");
objChoiceMidStr1.set_ChoiceStringValue("SEA");

Choice objChoiceMidStr2 = Factory.Choice.createInstance();
objChoiceMidStr2.set_ChoiceType(ChoiceType.STRING);
objChoiceMidStr2.set_DisplayName("Kirkland");
objChoiceMidStr2.set_ChoiceStringValue("KIR");

Choice objChoiceMidStr3 = Factory.Choice.createInstance();
objChoiceMidStr3.set_ChoiceType(ChoiceType.STRING);
objChoiceMidStr3.set_DisplayName("Bellevue");
objChoiceMidStr3.set_ChoiceStringValue("BEL");

// Create string-type choice objects and populate group node
Choice objChoiceStr1 = Factory.Choice.createInstance();
objChoiceStr1.set_ChoiceType(ChoiceType.MIDNODE_STRING);
objChoiceStr1.set_DisplayName("Washington");
objChoiceStr1.set_ChoiceValues(Factory.Choice.createList());
objChoiceStr1.get_ChoiceValues().add(objChoiceMidStr1);
objChoiceStr1.get_ChoiceValues().add(objChoiceMidStr2);
objChoiceStr1.get_ChoiceValues().add(objChoiceMidStr3);

Choice objChoiceStr2 = Factory.Choice.createInstance();
objChoiceStr2.set_ChoiceType(ChoiceType.STRING);
objChoiceStr2.set_ChoiceStringValue("OR");

// Set up LocalizedString object for this Choice object
LocalizedString objLocStr2 = Factory.LocalizedString.createInstance();
objLocStr2.set_LocaleName(objObjectStore.get_LocaleName());
objLocStr2.set_LocalizedText("Oregon");

// Create LocalizedStringList collection and add LocalizedString object
objChoiceStr2.set_DisplayNames(Factory.LocalizedString.createList());
objChoiceStr2.get_DisplayNames().add(objLocStr2);

Choice objChoiceStr3 = Factory.Choice.createInstance();
objChoiceStr3.set_ChoiceType(ChoiceType.STRING);
objChoiceStr3.set_ChoiceStringValue("CA");

// Set up LocalizedString object for this Choice object
LocalizedString objLocStr3 = Factory.LocalizedString.createInstance();
objLocStr3.set_LocaleName(objObjectStore.get_LocaleName());
objLocStr3.set_LocalizedText("Oregon");

// Create LocalizedStringList collection and add LocalizedString object
objChoiceStr3.set_DisplayNames(Factory.LocalizedString.createList());
objChoiceStr3.get_DisplayNames().add(objLocStr3);

// Create a string-type ChoiceList object 
com.filenet.api.admin.ChoiceList objChoiceListStr = Factory.ChoiceList.createInstance(objObjectStore);
objChoiceListStr.set_DataType(TypeID.STRING);

// Add choice items to choice list and save it
objChoiceListStr.set_ChoiceValues(Factory.Choice.createList());
objChoiceListStr.get_ChoiceValues().add(objChoiceStr1);
objChoiceListStr.get_ChoiceValues().add(objChoiceStr2);
objChoiceListStr.get_ChoiceValues().add(objChoiceStr3);
objChoiceListStr.set_DisplayName("String State List");
objChoiceListStr.save(RefreshMode.REFRESH);

System.out.println("Choice list created: " + objChoiceListStr.get_Name());
System.out.println(objChoiceListStr);

/****************************
 * Integer-type choice list * 
 ****************************/

// Create integer-type Choice objects for a group
Choice objChoiceMidInt1 = Factory.Choice.createInstance();
objChoiceMidInt1.set_ChoiceType(ChoiceType.INTEGER);
objChoiceMidInt1.set_DisplayName("Seattle");
objChoiceMidInt1.set_ChoiceIntegerValue(11);

Choice objChoiceMidInt2 = Factory.Choice.createInstance();
objChoiceMidInt2.set_ChoiceType(ChoiceType.INTEGER);
objChoiceMidInt2.set_DisplayName("Kirkland");
objChoiceMidInt2.set_ChoiceIntegerValue(12);

Choice objChoiceMidInt3 = Factory.Choice.createInstance();
objChoiceMidInt3.set_ChoiceType(ChoiceType.INTEGER);
objChoiceMidInt3.set_DisplayName("Bellevue");
objChoiceMidInt3.set_ChoiceIntegerValue(13);

// Create integer-type Choice objects and populate group node
Choice objChoiceInt1 = Factory.Choice.createInstance();
objChoiceInt1.set_ChoiceType(ChoiceType.MIDNODE_INTEGER);
objChoiceInt1.set_DisplayName("Washington");
objChoiceInt1.set_ChoiceValues(Factory.Choice.createList());
objChoiceInt1.get_ChoiceValues().add(objChoiceMidInt1);
objChoiceInt1.get_ChoiceValues().add(objChoiceMidInt2);
objChoiceInt1.get_ChoiceValues().add(objChoiceMidInt3);
objChoiceInt1.set_ChoiceIntegerValue(1);

Choice objChoiceInt2 = Factory.Choice.createInstance();
objChoiceInt2.set_ChoiceType(ChoiceType.INTEGER);
objChoiceInt2.set_DisplayName("Oregon");
objChoiceInt2.set_ChoiceIntegerValue(2);

Choice objChoiceInt3 = Factory.Choice.createInstance();
objChoiceInt3.set_ChoiceType(ChoiceType.INTEGER);
objChoiceInt3.set_DisplayName("California");
objChoiceInt3.set_ChoiceIntegerValue(3);

// Create an integer-type ChoiceList object 
com.filenet.api.admin.ChoiceList objChoiceListInt = Factory.ChoiceList.createInstance(objObjectStore);
objChoiceListInt.set_DataType(TypeID.LONG);

// Add choice items to choice list and save it
objChoiceListInt.set_ChoiceValues(Factory.Choice.createList());
objChoiceListInt.get_ChoiceValues().add(objChoiceInt1);
objChoiceListInt.get_ChoiceValues().add(objChoiceInt2);
objChoiceListInt.get_ChoiceValues().add(objChoiceInt3);
objChoiceListInt.set_DisplayName("Integer State List");
objChoiceListInt.save(RefreshMode.REFRESH);

System.out.println("Choice list created: " + objChoiceListInt.get_Name());
System.out.println(objChoiceListInt);

C# Example

/***************************
 * String-type choice list * 
 ***************************/

// Create string-type Choice objects for a group
IChoice objChoiceMidStr1 = Factory.Choice.CreateInstance();
objChoiceMidStr1.ChoiceType = ChoiceType.STRING;
objChoiceMidStr1.DisplayName = "Seattle";
objChoiceMidStr1.ChoiceStringValue = "SEA";

IChoice objChoiceMidStr2 = Factory.Choice.CreateInstance();
objChoiceMidStr2.ChoiceType = ChoiceType.STRING;
objChoiceMidStr2.DisplayName = "Kirkland";
objChoiceMidStr2.ChoiceStringValue = "KIR";

IChoice objChoiceMidStr3 = Factory.Choice.CreateInstance();
objChoiceMidStr3.ChoiceType = ChoiceType.STRING;
objChoiceMidStr3.DisplayName = "Bellevue";
objChoiceMidStr3.ChoiceStringValue = "BEL";

// Create string-type choice objects and populate group node
IChoice objChoiceStr1 = Factory.Choice.CreateInstance();
objChoiceStr1.ChoiceType = ChoiceType.MIDNODE_STRING;
objChoiceStr1.DisplayName = "Washington";
objChoiceStr1.ChoiceValues = Factory.Choice.CreateList();
objChoiceStr1.ChoiceValues.Add(objChoiceMidStr1);
objChoiceStr1.ChoiceValues.Add(objChoiceMidStr2);
objChoiceStr1.ChoiceValues.Add(objChoiceMidStr3);

IChoice objChoiceStr2 = Factory.Choice.CreateInstance();
objChoiceStr2.ChoiceType = ChoiceType.STRING;
objChoiceStr2.ChoiceStringValue = "OR";

// Set up LocalizedString object for this Choice object
ILocalizedString objLocStr2 = Factory.LocalizedString.CreateInstance();
objLocStr2.LocaleName = objObjectStore.LocaleName;
objLocStr2.LocalizedText = "Oregon";

// Create LocalizedStringList collection and add LocalizedString object
objChoiceStr2.DisplayNames = Factory.LocalizedString.CreateList();
objChoiceStr2.DisplayNames.Add(objLocStr2);

IChoice objChoiceStr3 = Factory.Choice.CreateInstance();
objChoiceStr3.ChoiceType = ChoiceType.STRING;
objChoiceStr3.ChoiceStringValue = "CA";

// Set up LocalizedString object for this Choice object
ILocalizedString objLocStr3 = Factory.LocalizedString.CreateInstance();
objLocStr3.LocaleName = objObjectStore.LocaleName;
objLocStr3.LocalizedText = "California";

// Create LocalizedStringList collection and add LocalizedString object
objChoiceStr3.DisplayNames = Factory.LocalizedString.CreateList();
objChoiceStr3.DisplayNames.Add(objLocStr3);

// Create a string-type ChoiceList object 
FileNet.Api.Admin.IChoiceList objChoiceListStr = Factory.ChoiceList.CreateInstance(objObjectStore);
objChoiceListStr.DataType = TypeID.STRING;

// Add choice items to choice list and save it
objChoiceListStr.ChoiceValues = Factory.Choice.CreateList();
objChoiceListStr.ChoiceValues.Add(objChoiceStr1);
objChoiceListStr.ChoiceValues.Add(objChoiceStr2);
objChoiceListStr.ChoiceValues.Add(objChoiceStr3);
objChoiceListStr.DisplayName = "String State List";
objChoiceListStr.Save(RefreshMode.REFRESH);

Console.WriteLine("Choice list created: " + objChoiceListStr.Name);
Console.WriteLine(objChoiceListStr);

/****************************
 * Integer-type choice list * 
 ****************************/

// Create integer-type Choice objects for a group
IChoice objChoiceMidInt1 = Factory.Choice.CreateInstance();
objChoiceMidInt1.ChoiceType = ChoiceType.INTEGER;
objChoiceMidInt1.DisplayName = "Seattle";
objChoiceMidInt1.ChoiceIntegerValue = 11;

IChoice objChoiceMidInt2 = Factory.Choice.CreateInstance();
objChoiceMidInt2.ChoiceType = ChoiceType.INTEGER;
objChoiceMidInt2.DisplayName = "Kirkland";
objChoiceMidInt2.ChoiceIntegerValue = 12;

IChoice objChoiceMidInt3 = Factory.Choice.CreateInstance();
objChoiceMidInt3.ChoiceType = ChoiceType.INTEGER;
objChoiceMidInt3.DisplayName = "Bellevue";
objChoiceMidInt3.ChoiceIntegerValue = 13;

// Create integer-type Choice objects and populate group node
IChoice objChoiceInt1 = Factory.Choice.CreateInstance();
objChoiceInt1.ChoiceType = ChoiceType.MIDNODE_INTEGER;
objChoiceInt1.DisplayName = "Washington";
objChoiceInt1.ChoiceValues = Factory.Choice.CreateList();
objChoiceInt1.ChoiceValues.Add(objChoiceMidInt1);
objChoiceInt1.ChoiceValues.Add(objChoiceMidInt2);
objChoiceInt1.ChoiceValues.Add(objChoiceMidInt3);
objChoiceInt1.ChoiceIntegerValue = 1;

IChoice objChoiceInt2 = Factory.Choice.CreateInstance();
objChoiceInt2.ChoiceType = ChoiceType.INTEGER;
objChoiceInt2.DisplayName = "Oregon";
objChoiceInt2.ChoiceIntegerValue = 2;

IChoice objChoiceInt3 = Factory.Choice.CreateInstance();
objChoiceInt3.ChoiceType = ChoiceType.INTEGER;
objChoiceInt3.DisplayName = "California";
objChoiceInt3.ChoiceIntegerValue = 3;

// Create an integer-type ChoiceList object 
FileNet.Api.Admin.IChoiceList objChoiceListInt = Factory.ChoiceList.CreateInstance(objObjectStore);
objChoiceListInt.DataType = TypeID.LONG;

// Add choice items to choice list and save it
objChoiceListInt.ChoiceValues = Factory.Choice.CreateList();
objChoiceListInt.ChoiceValues.Add(objChoiceInt1);
objChoiceListInt.ChoiceValues.Add(objChoiceInt2);
objChoiceListInt.ChoiceValues.Add(objChoiceInt3);
objChoiceListInt.DisplayName = "Integer State List";
objChoiceListInt.Save(RefreshMode.REFRESH); 

Console.WriteLine("Choice list created: " + objChoiceListInt.Name);
Console.WriteLine(objChoiceListInt);

Associating a Choice List with a Property Template

To associate a choice list with a property template, follow these steps:

  1. Find or create a property template that matches the type of ChoiceList object (integer or string) that you want to associate with it. (For example, an integer-type ChoiceList object must be associated with a PropertyTemplateInteger object and a string-type ChoiceList object must be associated with a PropertyTemplateString object.)
  2. Set the property template's ChoiceList property to the ChoiceList object.
  3. Call the property template's save method.

The following code example demonstrates how to associate a choice list with a property template:

Java Example

System.out.println("Type the symbolic name of the property template with which the choice list will be associated:");
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
String strSearchPT = in.readLine();    				

String prpSymbolicName;        			  
	        			
Iterator iter = objObjectStore.get_PropertyTemplates().iterator();
PropertyTemplate objPropertyTemplate = null;

// Loop until property template found in object store
while (iter.hasNext())
{
   objPropertyTemplate = (PropertyTemplate) iter.next();
   prpSymbolicName = objPropertyTemplate.get_SymbolicName();

   if (prpSymbolicName.equalsIgnoreCase(strSearchPT))
   {
      // PropertyTemplate object found
      System.out.println("Property template selected: " + prpSymbolicName);
      System.out.println(objPropertyTemplate);
	  
      System.out.println("Type the name of the choice list to associate with the property template:");
      String clSearchName = in.readLine();

      String prpName;

      Iterator iter2 = objObjectStore.get_ChoiceLists().iterator();
      com.filenet.api.admin.ChoiceList objChoiceList = null;

      // Loop until choice list found
      while (iter2.hasNext())
      {
         objChoiceList = (com.filenet.api.admin.ChoiceList) iter2.next();
         prpName = objChoiceList.get_Name();

         if (prpName.equalsIgnoreCase(clSearchName))
         {
            // ChoiceList object found
            System.out.println("Choice list selected: " + prpName);
            System.out.println(objChoiceList);
			
            // Add Choice List to property template
            objPropertyTemplate.set_ChoiceList(objChoiceList);
            objPropertyTemplate.save(RefreshMode.REFRESH);
         }
      }
   }
}

C# Example

Console.WriteLine("Type the symbolic name of the property template with which the choice list will be associated:");
String strSearchPT = Console.ReadLine(); 	

String prpSymbolicName;        			
	  
// Loop until property template found in object store
foreach (IPropertyTemplate objPropertyTemplate in objObjectStore.PropertyTemplates)
{
   prpSymbolicName = objPropertyTemplate.SymbolicName;

   if (prpSymbolicName.Equals(strSearchPT, StringComparison.OrdinalIgnoreCase))
   {
      // PropertyTemplate object found
      Console.WriteLine("Property template selected: " + prpSymbolicName);
      Console.WriteLine(objPropertyTemplate);
	  
      Console.WriteLine("Type the name of the choice list to associate with the property template:");
      String strSearchCL = Console.ReadLine();

      String prpName;

      // Loop until choice list found
      foreach (FileNet.Api.Admin.IChoiceList objChoiceList in objObjectStore.ChoiceLists)
      {
         prpName = objChoiceList.Name;

         if (prpName.Equals(strSearchCL, StringComparison.OrdinalIgnoreCase))
         {
            // ChoiceList object found
            Console.WriteLine("Choice list selected: " + prpName);
            Console.WriteLine(objChoiceList);
            Console.WriteLine("Press any key to continue");
            Console.ReadLine();
			
            // Add Choice List to property template
            objPropertyTemplate.ChoiceList = objChoiceList;
            objPropertyTemplate.Save(RefreshMode.REFRESH);
         }
      }
   }
}

Associating a Choice List with a Property Definition

To associate a choice list with a property definition, follow these steps:

  1. Find or create a property definition that matches the type of ChoiceList object (integer or string) you want to associate with it. (For example, an integer-type ChoiceList object must be associated with a PropertyDefinitionInteger object and a string-type ChoiceList object must be associated with a PropertyDefinitionString object.)
  2. Set the property definition's ChoiceList property to the ChoiceList object.
  3. Call the save method of the class definition to which the property definition belongs.

The following codes example demonstrates how to associate a choice list with a property definition:

Java Example

System.out.println("Type the symbolic name of the class definition in which the property definition is located:");
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
String strSearchCD = in.readLine();    		

// Construct a property filter to ensure PropertyDefinitions property of class definition is returned as evaluated
PropertyFilter objPropertyFilter = new PropertyFilter();
objPropertyFilter.addIncludeType(0, null, true, FilteredPropertyType.ANY, null); 
			
// Fetch selected class definition from the server
ClassDefinition objClassDefinition = Factory.ClassDefinition.fetchInstance(objObjectStore, strSearchCD, objPropertyFilter);

System.out.println("Type the symbolic name of the property definition with which the choice list will be associated:");
String strSearchPD = in.readLine();    				
		
String prpSymbolicName;        			  
	
Iterator iter = objClassDefinition.get_PropertyDefinitions().iterator();
PropertyDefinition objPropertyDefinition = null;

// Loop until property definition found in object store
while (iter.hasNext())
{
   objPropertyDefinition = (PropertyDefinition) iter.next();
   prpSymbolicName = objPropertyDefinition.get_SymbolicName();

   if (prpSymbolicName.equalsIgnoreCase(strSearchPD))
   {
      // PropertyTemplate object found
      System.out.println("Property definition selected: " + prpSymbolicName);
      System.out.println(objPropertyDefinition);
	  
      System.out.println("Type the name of the choice list to associate with the property template:");
      String clSearchName = in.readLine();

      String prpName;

      Iterator iter2 = objObjectStore.get_ChoiceLists().iterator();
      com.filenet.api.admin.ChoiceList objChoiceList = null;

      // Loop until choice list found
      while (iter2.hasNext())
      {
         objChoiceList = (com.filenet.api.admin.ChoiceList) iter2.next();
         prpName = objChoiceList.get_Name();

         if (prpName.equalsIgnoreCase(clSearchName))
         {
            // ChoiceList object found
            System.out.println("Choice list selected: " + prpName);
            System.out.println(objChoiceList);
			
            // Add Choice List to property definition	
            objPropertyDefinition.set_ChoiceList(objChoiceList);
            objClassDefinition.save(RefreshMode.REFRESH);
         }
      }
   }
}

C# Example

Console.WriteLine("Type the symbolic name of the class definition in which the property definition is located:");
String strSearchCD = Console.ReadLine();

// Construct a property filter to ensure PropertyDefinitions property of CD is returned as evaluated
PropertyFilter objPropertyFilter = new PropertyFilter();
objPropertyFilter.AddIncludeType(0, null, true, FilteredPropertyType.ANY, null); 
			
// Fetch selected class definition from the server
IClassDefinition objClassDefinition = Factory.ClassDefinition.FetchInstance(objObjectStore, strSearchCD, objPropertyFilter);

String prpSymbolicName;    
Console.WriteLine("Type the symbolic name of the property definition with which the choice list will be associated:");
String strSearchPD = Console.ReadLine();
		 
// Get PropertyDefinitions property from the property cache	        	
IPropertyDefinitionList objPropertyDefinitions = objClassDefinition.PropertyDefinitions;   	        			
	  
// Loop until property definition found
foreach (IPropertyDefinition objPropertyDefinition in objPropertyDefinitions)
{
   prpSymbolicName = objPropertyDefinition.SymbolicName;

   if (prpSymbolicName.Equals(strSearchPD, StringComparison.OrdinalIgnoreCase))
   {
      // PropertyDefinition object found
      Console.WriteLine("Property definition selected: " + prpSymbolicName);
      Console.WriteLine(objPropertyDefinition);
      Console.WriteLine("Press any key to continue");
      Console.ReadLine();
	  
      Console.WriteLine("Type the name of the choice list to associate with the property definition:");
      String strSearchCL = Console.ReadLine();

      String prpName;

      // Loop until choice list found
      foreach (FileNet.Api.Admin.IChoiceList objChoiceList in objObjectStore.ChoiceLists)
      {
         prpName = objChoiceList.Name;

         if (prpName.Equals(strSearchCL, StringComparison.OrdinalIgnoreCase))
         {
            // ChoiceList object found
            Console.WriteLine("Choice list selected: " + prpName);
            Console.WriteLine(objChoiceList);
            Console.WriteLine("Press any key to continue");
            Console.ReadLine();
			
            // Add Choice List to property definition
            objPropertyDefinition.ChoiceList = objChoiceList;
            objClassDefinition.Save(RefreshMode.REFRESH);
         }
      }
   }		 
}