Query on property that may or may not exist | Community
Skip to main content
Level 4
October 16, 2015
Solved

Query on property that may or may not exist

  • October 16, 2015
  • 4 replies
  • 4609 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

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)

4 replies

smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

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)

Lokesh_Shivalingaiah
Level 10
October 16, 2015

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

BenSt10Author
Level 4
October 16, 2015

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");
smacdonald2008
Level 10
October 16, 2015

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