Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Query on property that may or may not exist

Avatar

Level 5

I have a rather complicated query that fails on a search for the property "hideInNav." I'm trying to get all pages where this is not true, but I can't figure out the operation that accomplishes this.

I've tried the following:

2_property=hideInNav
2_property.operation=like
2_property.1_value=%
2_property.2_value=false

and

2_property=hideInNav
2_property.operation=unequals
2_property.value=true

Neither returns the list of pages I'm looking for. If the hideInNav property hasn't been set, it seems that there's no ability query on it.

1 Accepted Solution

Avatar

Correct answer by
Level 10

You are trying to base a search on the hideInNav prop. However - basing an AEM Query on a prop that may or may not exist may not work if the prop is not defined.  

The best thing to so is to get a result set (maybe query pages - based on a path) and then check to see if the prop is there. You can invoke this method to detemine if a property exists on a node:

http://www.day.com/specs/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#hasProperty(java.lang.String)

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

You are trying to base a search on the hideInNav prop. However - basing an AEM Query on a prop that may or may not exist may not work if the prop is not defined.  

The best thing to so is to get a result set (maybe query pages - based on a path) and then check to see if the prop is there. You can invoke this method to detemine if a property exists on a node:

http://www.day.com/specs/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#hasProperty(java.lang.String)

Avatar

Level 10

You can use the 'PropertyExistence' check using the JQOM query. refer [1] for the same. we are also releasing an article on JQOM query next week

[1] http://www.day.com/specs/jcr/2.0/6_Query.html

Avatar

Level 5

On a whim I tried the following, which seems to do the trick: 

map.put("group.p.or", "true"); map.put("group.1_property", "hideInNav"); map.put("group.1_property.operation","like"); map.put("group.1_property.value","false"); map.put("group.2_property", "hideInNav"); map.put("group.2_property.operation","not");

Avatar

Level 10

that looks good - I will ask the AEM doc team to add this to the documentation so it helps AEM users.