May 27, 2020
Estimated Post Reading Time ~

AEM Issue while reading multifield values using Node API

How to read multifield  using Node API
if you configure one item it will set String type to the content node.

if you configure more than one items it will set as String[] type to the component.

Below snippet code works for both String and String[] types

if(currentNode.hasProperty("multifieldProp")){
       
 Value[] options = (currentNode.getProperty("multifieldProp").isMultiple()) ? currentNode.getProperty("multifieldProp").getValues() : null;
 if (options == null) {//has single value
  Value[] option = {currentNode.getProperty( "optionsConfig" ).getValue()};
  options = option;
 } 
 if ( options != null ) {
   for(Value option : options){
   System.out.println(option);
   }
 }
       
}



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.