Tuesday, March 16, 2010

SAP Portal - Obtain Property from IResource

If, for example, you have created a pre-defined property for KM document, called it "MyProperty", you can obtain its value after obtain an IResource object.
IPropertyName myPropertyName = PropertyName.getPN("http://sapportals.com/xmlns/cm", "MyProperty");
IProperty myProperty = resource.getProperty(myPropertyName);
if (myProperty != null) {
String myPropertyValue = myProperty.getStringValue();
}
Easy?

Now what if the MyProperty is Multi-Valued? Here is the code.
List values = property.getValues();
for (Iterator valuesIterator = values.iterator(); valuesIterator.hasNext();) {
String element = (String) valuesIterator.next();
}

No comments: