To create a CustomObject
object, follow these steps:
Factory.CustomObject.createInstance
method. save
method. The following code example demonstrates how to create a CustomObject
object:
Java Example
// Create CustomObject object CustomObject objCustomObject = Factory.CustomObject.createInstance(objObjectStore, "CustomObject"); objCustomObject.save(RefreshMode.REFRESH); System.out.println("Custom object created: " + objCustomObject.get_Name()); System.out.println(objCustomObject);
C# Example
// Create CustomObject object ICustomObject objCustomObject = Factory.CustomObject.CreateInstance(objObjectStore, "CustomObject"); objCustomObject.Save(RefreshMode.REFRESH); Console.WriteLine("Custom object created: " + objCustomObject.Name); Console.WriteLine(objCustomObject);
The following code example demonstrates how to retrieve a CustomObject
object:
Java Example
System.out.println("Type the path name of the CustomObject object to retrieve (/<folder name>/<containment name>):"); InputStreamReader converter = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(converter); String strPath = in.readLine(); // Retrieve CustomObject object CustomObject objCustomObject = Factory.CustomObject.fetchInstance(objObjectStore, strPath, null); objCustomObject.save(RefreshMode.REFRESH); System.out.println("CustomObject object retrieved: " + objCustomObject.get_Name()); System.out.println(objCustomObject);
C# Example
Console.WriteLine("Type the path name of the CustomObject object to retrieve (/<folder name>/<containment name>):"); String strPath = Console.ReadLine(); // Retrieve CustomObject object ICustomObject objCustomObject = Factory.CustomObject.FetchInstance(objObjectStore, strPath, null); objCustomObject.Save(RefreshMode.REFRESH); Console.WriteLine("CustomObject object retrieved: " + objCustomObject.Name); Console.WriteLine(objCustomObject);
To create a subclass of the CustomObject
class and add a custom name property, follow these steps:
Factory.ClassDefinition.fetchInstance
method to fetch the ClassDefinition
object that defines the CustomObject
class. ClassDefinition
object's createSubclass
method to create a new ClassDefinition
object as a subclass of the CustomObject
class.Factory.LocalizedString.createInstance
to create a LocalizedString
object and set its LocalizedText and LocaleName properties.Factory.LocalizedString.createList
to create a LocalizedStringList
collection object and set it to the new ClassDefinition
object's DisplayNames property.ClassDefinition
object's save
method to save it.Factory.PropertyTemplateString.createInstance
method to create a PropertyTemplateString
object. PropertyTemplateString
object's Cardinality property to specify single cardinality.Factory.LocalizedString.createInstance
method to create a LocalizedString
object and set its LocalizedText and LocaleName properties.Factory.LocalizedString.createList
method to create a LocalizedStringList
collection object and set it to the new PropertyTemplateString
object's DisplayNames property.PropertyTemplateString
object's save
method to save it.PropertyTemplateString
object's createClassProperty
method to create a new PropertyDefinitionString
object.PropertyDefinitionString
object's IsNameProperty to true
to designate it as the name property for the new CustomObject
subclass.PropertyDefinitionList
collection object from the PropertyDefinitions property of the new ClassDefinition
object and call its add
method to add the new PropertyDefinitionString
object to its collection.ClassDefinition
object's save
method to save the changes to its property definitions.The following code example demonstrates how to create a subclass of the CustomObject
class and add a custom name property:
Java Example
System.out.println("Type the name of the new CustomObject subclass:"); InputStreamReader converter = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(converter); String strClassName = in.readLine(); // Fetch CustomObject class definition ClassDefinition objClassDefCO = Factory.ClassDefinition.fetchInstance(objObjectStore, GuidConstants.Class_CustomObject, null); // Create a subclass of the CustomObject class ClassDefinition objClassDefCOSub = objClassDefCO.createSubclass(); // Set up locale LocalizedString objLocStrCD = Factory.LocalizedString.createInstance(); objLocStrCD.set_LocalizedText(strClassName); objLocStrCD.set_LocaleName(objObjectStore.get_LocaleName()); // Create LocalizedStringList collection objClassDefCOSub.set_DisplayNames(Factory.LocalizedString.createList()); objClassDefCOSub.get_DisplayNames().add(objLocStrCD); // Save new class definition to the server objClassDefCOSub.save(RefreshMode.REFRESH); System.out.println("New CustomObject subclass: " + objClassDefCOSub.get_Name()); System.out.println(objClassDefCOSub); // Construct property filter to ensure PropertyDefinitions property of class definition is returned as evaluated PropertyFilter pf = new PropertyFilter(); pf.addIncludeType(0, null, Boolean.TRUE, FilteredPropertyType.ANY, null); // Create property template for a single-valued string property System.out.println("Type the name of the new custom name property:"); String strTemplateName = in.readLine(); PropertyTemplateString objPropTemplate = Factory.PropertyTemplateString.createInstance(objObjectStore); // Set cardinality of properties that will be created from the property template objPropTemplate.set_Cardinality(Cardinality.SINGLE); // Set up locale LocalizedString objLocStrPT = Factory.LocalizedString.createInstance(); objLocStrPT.set_LocalizedText(strTemplateName); objLocStrPT.set_LocaleName(objObjectStore.get_LocaleName()); // Create LocalizedStringList collection objPropTemplate.set_DisplayNames(Factory.LocalizedString.createList()); objPropTemplate.get_DisplayNames().add(objLocStrPT); // Save new property template to the server objPropTemplate.save(RefreshMode.REFRESH); // Create property definition from property template PropertyDefinitionString objPropDef = (PropertyDefinitionString) objPropTemplate.createClassProperty(); // Set custom property as the designated name property objPropDef.set_IsNameProperty(true); // Get PropertyDefinitions property from the property cache PropertyDefinitionList objPropDefs = objClassDefCOSub.get_PropertyDefinitions(); // Add new property definition to class definition objPropDefs.add(objPropDef); objClassDefCOSub.save(RefreshMode.REFRESH); System.out.println("New property definition for custom name property: "); System.out.println(objPropDef);
C# Example
Console.WriteLine("Type the name of the new CustomObject subclass:"); String strClassName = Console.ReadLine(); // Retrieve CustomObject class definition IClassDefinition objClassDefCO = Factory.ClassDefinition.FetchInstance(objObjectStore, GuidConstants.Class_CustomObject, null); // Create a subclass of the CustomObject class IClassDefinition objClassDefCOSub = objClassDefCO.CreateSubclass(); // Set up locale ILocalizedString objLocStrCD = Factory.LocalizedString.CreateInstance(); objLocStrCD.LocalizedText = strClassName; objLocStrCD.LocaleName = objObjectStore.LocaleName; // Create LocalizedStringList collection objClassDefCOSub.DisplayNames = Factory.LocalizedString.CreateList(); objClassDefCOSub.DisplayNames.Add(objLocStrCD); // Save new class definition to the server objClassDefCOSub.Save(RefreshMode.REFRESH); Console.WriteLine("New CustomObject subclass: " + objClassDefCOSub.Name); Console.WriteLine(objClassDefCOSub); // Construct property filter to ensure PropertyDefinitions property of class definition is returned as evaluated PropertyFilter pf = new PropertyFilter(); pf.AddIncludeType(0, null, true, FilteredPropertyType.ANY, null); // Create property template for a single-valued string property Console.WriteLine("Type the name of the new custom name property:"); String strTemplateName = Console.ReadLine(); IPropertyTemplateString objPropTemplate = Factory.PropertyTemplateString.CreateInstance(objObjectStore); // Set cardinality of properties that will be created from the property template objPropTemplate.Cardinality = Cardinality.SINGLE; // Set up locale ILocalizedString objLocStrPT = Factory.LocalizedString.CreateInstance(); objLocStrPT.LocalizedText = strTemplateName; objLocStrPT.LocaleName = objObjectStore.LocaleName; // Create LocalizedStringList collection objPropTemplate.DisplayNames = Factory.LocalizedString.CreateList(); objPropTemplate.DisplayNames.Add(objLocStrPT); // Save new property template to the server objPropTemplate.Save(RefreshMode.REFRESH); // Create property definition from property template IPropertyDefinitionString objPropDef = (IPropertyDefinitionString) objPropTemplate.CreateClassProperty(); // Set custom property as the designated name property objPropDef.IsNameProperty = true; // Get PropertyDefinitions property from the property cache IPropertyDefinitionList objPropDefs = objClassDefCOSub.PropertyDefinitions; // Add new property definition to class definition objPropDefs.Add(objPropDef); objClassDefCOSub.Save(RefreshMode.REFRESH); Console.WriteLine("New property definition for custom name property: "); Console.WriteLine(objPropDef); Console.WriteLine("Press any key to end"); Console.ReadLine();