cancel
Showing results for 
Search instead for 
Did you mean: 

Set value of multiselect property

Former Member
0 Kudos

Hi,

I have created a multiselect metadata property.

How can I set its value programmatically?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Detlev,

Thanks for your answer. I am able to set multivalued property of a resource. But the problem I am facing now is, property is set only if it has some default value initially. If no value is set, then I am getting exception as 'property is not multivalued'.

My code is :

final String CREATED_BY_PROP_PREFIX =

"http://sapportals.com/xmlns/cm";

IPortalComponentRequest request =

(IPortalComponentRequest) this.getRequest();

try {

IUser user =

WPUMFactory.getUserFactory().getEP5User(request.getUser());

ResourceContext ctxt = new ResourceContext(user);

RID rid = RID.getRID("xyz/content/a.xml");

IResource res =

ResourceFactory.getInstance().getResource(rid, ctxt);

if (res != null) {

IPropertyName propName =

new PropertyName(CREATED_BY_PROP_PREFIX, "propname");

IProperty p = res.getProperty(propName);

IMutableProperty mutableProp = null;

mutableProp = p.getMutable();

mutableProp.addValue("val1");//here is exception

mutableProp.addValue("Val2");

res.setProperty(mutableProp);

}

} catch (Exception e) { }

detlev_beutner
Active Contributor
0 Kudos

Hi Deepti,

Did you try to call <i>setValues(yourValueList)</i> initially? If that works, you could go one step further and call <i>setValues(new ArrayList())</i> and afterwards call add values.

Please check and come back with the results.

INFO: Please mark code fragments as yours with the CODE marker of the SDN editor, making it much more readable.

Hope it helps

Detlev

detlev_beutner
Active Contributor
0 Kudos

Hi Deepti,

See https://media.sdn.sap.com/javadocs/NW04/SPS15/km/com/sapportals/wcm/repository/IMutableProperty.html - there are different methods for setting multi-valued property values (addValue, setValue with index, setValues).

Hope it helps

Detlev