Expand my Community achievements bar.

SOLVED

AEM Query for property with no value

Avatar

Community Advisor

I am looking for writing an AEM query using the Query Builder Debugger. My goal is to look for nodes with property "sectionEmail" and value as blank () No Value. I tried something like this below

path=/content/myproject

type=cq:Page

property=sectionEmail

property.value=

As a result I just get all the nodes with the property "sectionEmail" regardless of whther it has a value or not.

Any idea on corrections needed to make on this?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

The solution I was suggesting is to get all the nodes with the property=sectionEmail  and then once you have those , iterate over the property nodes and look for the nodes which has empty value .

Thanks

Veena

View solution in original post

11 Replies

Avatar

Level 8

You can do the following and remove the property.value

property.operator=not

You may also need to add @jcr:content/ to the property name, so the full thing would look like this:

path=/content/myproject 

type=cq:Page 

property=@jcr:content/sectionEmail 

property.operation=not

Avatar

Community Advisor

Sorry for delayed response. I tried above query but I still dont see my results.

I went and added a property 'test' to a node at '/content/myproject/mysection/jcr:content'. First I gave it a value as 'testvalue' and when I did a simple query with property.value=testvalue, I was able to see the single result. I removed the value and saved it.

Then I ran the suggested query as

path=/content/myproject

type=cq:Page

property=@jcr:content/test  

property.operation=not

I see no results for that (Also tried property.operator=not)

Avatar

Level 8

I think the difference is that you removed the value, meaning that the property name still exists on the node but has an empty string - when you save an empty value using a dialog, the property itself is removed - so the not operation looks for the property not being on the node at all.  Go ahead and delete the "test" property rather than give it an empty value and the query should return that page.

Avatar

Community Advisor

Ok, yes I thought so, but I am trying to specifically find if there are any such properties with no value in the repository. Apologies if I was not able to explain what was required more clearly in my initial question

Avatar

Level 8

Not to my knowledge with the query builder.  Instead of setting the value to blank, could you set it to "none" and query for "none" instead?

Avatar

Community Advisor

Ok will try and update..Putting the value as none and searching for it might work. But thats not exactly the required case.

I remember trying null, '' , "" ..etc to see if that picks up the node in results. Again the value was still blank. But didn't work

Thanks for prompt replies

Avatar

Community Advisor

One workaround is to fetch all the nodes with properties and doing a node and property operation to check if the value is empty.

One question ,

     If you author a dialog with empty field (leave a field blank), obviously the property is not going to be present on the node once you submit the dialog. In that case the query suggested by leeasling​ is the exact solution.

     How are you setting an empty property to a node? Through a back end Java class or service ?

Thanks

Veena

Avatar

Community Advisor

Yes via backend Java service. This was more of a check we wanted to do, but not needed now. But out of curiosity I posted this question, that in case such situation happens how can we find how many are there..and so on..

How can I do that? Unable to understand it. If possible can you write query line for that?

Avatar

Correct answer by
Community Advisor

The solution I was suggesting is to get all the nodes with the property=sectionEmail  and then once you have those , iterate over the property nodes and look for the nodes which has empty value .

Thanks

Veena

Avatar

Community Advisor

Thanks Veena. Although I was looking for something directly on the query builder debugger tool, since this query was more for information purposes and currently there is no intention of writing a code for this, I think the answer you mentioned would give me correct results I am looking for.

Meanwhile if anyone can come up with a query that can go directly on QB Tool, please post, Thanks

Avatar

Level 7

Hi snbaem,

Sorry i know i am late, but this might help other folks, Yes we can achieve it through our tool itself. Their is no predicate for checking empty value, but we can achieve the same by using xpath queries. Like below:-

/jcr:root/content/dam//*[fn:name() = 'jcr:content' and @name= ""]

fn:name is optional, added to make query more restrictive.

/jcr:root/content/dam//*[@name= ""]

You can see detail information about it and how to use it here http://www.aemcq5tutorials.com/tutorials/adobe-aem-cq5-tutorials/aem-query-builder/