cancel
Showing results for 
Search instead for 
Did you mean: 

Remove a Custom Property

Former Member
0 Kudos

Hi all,

I created a custom property via KM API. I need to delete it from a specific resource.

When I try to delete it via IResource.deleteProperty() method, I get an exception (PropertyMandatoryException).

I think the exception is caused by the PropertyDef flag: isRequired = true.

I didn't find any method to modify an existing propertyDef associated to the my Property instance in order to turn isRequired flag false.

Any idea to solve this problem?

Thanks

Marco

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Marco,

please try the following:

create a new property with the name of the custom property and property def isRequired = false:

PropertyName name = ...

Property oldProp = resource.getProperty(name);

PropertyDef oldDef = oldProp.getPropertyDef();

PropertyDef def = new PropertyDef(oldDef.getType(), oldDef.isMultivalued(), false, ....);

Property prop = new Property(name, def, oldProp.getValue());

set this property to the resource in question

resource.setProperty(prop);

and afterwards delete the property from the resource

resource.deleteProperty(name);

If this may not work you have to delete the entire resource an create a new one except this property.

Regards, Klaus