cancel
Showing results for 
Search instead for 
Did you mean: 

Adding and Setting New Custom Properties in KM

Former Member
0 Kudos

Hello,

I am creating and setting the custom properties using KM APIs

Here is a code for that

IResource resource= ResourceFactory.getInstance().getResource(aRid, rContext);

IPropertyName propertyName = (IPropertyName)new PropertyName(NAMESPACE, "Test");

IProperty propertyValued = (IProperty)resource.getProperty(propertyName);

if (propertyValued == null) {

propertyValued = new Property(propertyName,"testing123");

resource.setProperty(propertyValued);

}

But I am getting a null pointer exception.

Can anybody suggest?

Thanks

Raj

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Raj

I tried this for a custom property(named Department).

// getting and setting the properties of a KM Document(Property Name:Department)

IPropertyName propName = (IPropertyName) new PropertyName("http://sapportals.com/xmlns/cm", "Department");

IProperty prop = aResource.getProperty(propName);

IMutableProperty mutableProp = prop.getMutable();

mutableProp.setStringValue("Finance");

aResource.setProperty(mutableProp);

This code works for the properties that are not readonly.

Regards

Geogi

Former Member
0 Kudos

hello raj,

instead of using IProperty propertyValued = (IProperty)resource.getProperty(propertyName);

,try using

IMutableProperty propertyValued = (IMutableProperty)resource.getProperty(propertyName);

with regards,

srinath

former_member441228
Active Participant
0 Kudos

IMutableProperty is just an extension of IProperty and as such doesn't explain any NPE.

former_member441228
Active Participant
0 Kudos

Please let us know some details on the NPE first, things like the stack trace and the reason.