Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Level 7

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.

View solution in original post

3 Replies

Avatar

Level 3

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 3


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

Correct answer by
Level 7

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.