To create a choice list, follow these steps:
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);
To associate a choice list with a property template, follow these steps:
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 = null;
String clSearchName = null;
String prpSymbolicName;
String prpName;
try {
String strSearchPT = in.readLine();
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
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("Type the name of the choice list to associate with the property template:");
try {
String clSearchName = in.readLine();
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
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);
// Add Choice List to property template
objPropertyTemplate.set_ChoiceList(objChoiceList);
objPropertyTemplate.save(RefreshMode.REFRESH);
}
}
}
}
C# Example
String strSearchPT = null;
String strSearchCL = null;
String prpSymbolicName;
String prpName;
Console.WriteLine("Type the symbolic name of the property template with which the choice list will be associated:");
strSearchPT = Console.ReadLine();
// 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("Type the name of the choice list to associate with the property template:");
strSearchCL = Console.ReadLine();
// 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);
// Add Choice List to property template
objPropertyTemplate.ChoiceList = objChoiceList;
objPropertyTemplate.Save(RefreshMode.REFRESH);
}
}
}
}
To associate a choice list with a property definition, follow these steps:
The following codes example demonstrates how to associate a choice list with a property definition:
Java Example
static PropertyFilter objPropertyFilter = new PropertyFilter();
...
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 = null;
String strSearchPD = null;
String clSearchName = null;
String prpSymbolicName;
String prpName;
try {
String strSearchCD = in.readLine();
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
objPropertyFilter.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.PROPERTY_DEFINITIONS, 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:");
try {
String strSearchPD = in.readLine();
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
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))
{
// PropertyDefinition object found
System.out.println("Property definition selected: " + prpSymbolicName);
System.out.println("Type the name of the choice list to associate with the property template:");
try {
String clSearchName = in.readLine();
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
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);
// Add Choice List to property definition
objPropertyDefinition.set_ChoiceList(objChoiceList);
objClassDefinition.save(RefreshMode.REFRESH);
}
}
}
}
C# Example
static PropertyFilter objPropertyFilter = new PropertyFilter();
...
String strSearchCD = null;
String strSearchPD = null;
String strSearchCL = null;
String prpSymbolicName;
String prpName;
Console.WriteLine("Type the symbolic name of the class definition in which the property definition is located:");
strSearchCD = Console.ReadLine();
objPropertyFilter.AddIncludeProperty(new FilterElement(null, null, null, PropertyNames.PROPERTY_DEFINITIONS, null));
// Fetch selected class definition from the server
IClassDefinition objClassDefinition = Factory.ClassDefinition.FetchInstance(objObjectStore, strSearchCD, objPropertyFilter);
Console.WriteLine("Type the symbolic name of the property definition with which the choice list will be associated:");
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("Type the name of the choice list to associate with the property definition:");
strSearchCL = Console.ReadLine();
// 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);
// Add Choice List to property definition
objPropertyDefinition.ChoiceList = objChoiceList;
objClassDefinition.Save(RefreshMode.REFRESH);
}
}
}
}
The code for dissociating a choice list from a property template or from a property definition is nearly identical to associating a choice list (see previous examples). The only difference is that you set the ChoiceList property to null on the property template or property definition. For example:
Java Example
// Remove Choice List from property definition
objPropertyDefinition.set_ChoiceList(null);
objClassDefinition.save(RefreshMode.REFRESH);
C# Example
// Remove Choice List to property definition
objPropertyDefinition.ChoiceList = null;
objClassDefinition.Save(RefreshMode.REFRESH);