Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

AEM asCS ACS-Commons javax.jcr.ValueFormatException: Can not assign a single value to multi-valued property:

Avatar

Level 1

Hi ,

We are trying to import data from manage-controlled-processes.html getting below error

Caused by: javax.jcr.ValueFormatException: Can not assign a single value to multi-valued property:org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.setProperty(NodeDelegate.java:501) at org.apache.jackrabbit.oak.jcr.session.NodeImpl$38.perform(NodeImpl.java:1448) at org.apache.jackrabbit.oak.jcr.session.NodeImpl$38.perform(NodeImpl.java:1435) at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:229) at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:113) at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1435) at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:377) at

3 Replies

Avatar

Level 2

The root cause of the above exception is because you trying to set non array value to a multifield property. Initialise an array and add the required value to the array and set the array as the value of the property.

Avatar

Level 2


Use any one of the below condition before updating the property value

Sling API
String val = "test";
ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class);
if(modifiableValueMap.get("someproperty").getClass().isArray()) {
 modifiableValueMap.put("someproperty", new String[]{val});
} else {
   modifiableValueMap.put("someproperty", val);
}

JCR API
Property property = node.getProperty("someproperty");
if(property.isMultiple()) {
  node.setProperty("someproperty", new String[]{val});
} else {
    node.setProperty("someproperty", val);

}

 

Avatar

Level 3

Hi @upendarme1 
If you’re dealing with a multi-valued property (e.g., a tag field), make sure you’re providing an array or list of values, not a single value. For example, if you’re setting tags, use an array of tag strings 

setProperty("tags", new String[]{"tag1", "tag2", "tag3"})


Check the specific line of code where the error occurs (e.g., NodeImpl.setProperty(NodeImpl.java:377)). Inspect the property name and value being set to identify any discrepancies.