Expand my Community achievements bar.

SOLVED

Query to fetch assets with either offTime doesn't exists or offTime greater than current time.

Avatar

Level 6

Please see my query below.

p.limit=-1
p.offset=0
path=/content/dam
type=dam:Asset

1_property=jcr:content/cq:lastReplicationAction_scene7
1_property.value=Activate

 

2_property=jcr:content/cq:lastReplicationAction
2_property.value=Activate

3_group.or=true

3_group.1_property=jcr:content/metadata/custom:assetType

3_group.1_property.1_value=image

3_group.1_property.2_value=document

3_group.1_property.1.operation=equals

3_group.1_property.2.operation=equals

 

4_group.or=true

4_group.1_property.operation=not

4_group.1_property=jcr:content/offTime

4_group.2_daterange.property=jcr:content/offTime

4_group.2_daterange.operation=>=

4_group.2_daterange.lowerBound=1729147820649

 

orderby.sort=asc

orderby=@jcr:content/jcr:lastModified



The corresponding XPath generated is,

/jcr:root/content/dam//element(*, dam:Asset)
[
((jcr:content/metadata/@custom:assetType = 'document' or jcr:content/metadata/@custom:assetType = 'image'))
and (not(jcr:content/@offtime)
and (jcr:content/@offtime > xs:dateTime('2024-10-17T06:50:20.649Z')))
and (jcr:content/@cQ:lastReplicationAction_scene7 = 'Activate' and jcr:content/@cQ:lastReplicationAction = 'Activate')
]
order by jcr:content/@jcr:lastModified

But what I'm looking is those assets where the offTime doesn't exist or offTime greater than current time, which should be an OR condition. But what I'm getting is an AND condition. How do I solve this?


1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @jezwn ,

Please try below one

p.limit=-1
p.offset=0
path=/content/dam
type=dam:Asset

1_property=jcr:content/cq:lastReplicationAction_scene7
1_property.value=Activate

2_property=jcr:content/cq:lastReplicationAction
2_property.value=Activate

3_group.p.or=true

3_group.1_property=jcr:content/metadata/custom:assetType
3_group.1_property.1_value=image
3_group.1_property.2_value=document
3_group.1_property.1.operation=equals
3_group.1_property.2.operation=equals

4_group.p.or=true

4_group.1_property.operation=exists
4_group.1_property=jcr:content/offTime
4_group.1_property.value=false

4_group.2_daterange.property=jcr:content/offTime
4_group.2_daterange.operation=>=
4_group.2_daterange.lowerBound=1729147820649

orderby.sort=asc
orderby=@jcr:content/jcr:lastModified

Use group.p.or=true instead of group.or=true

Thanks

View solution in original post

7 Replies

Avatar

Community Advisor

Hi @jezwn ,

You may try below xpath once,

/jcr:root/content/dam//element(*, dam:Asset)
[
((jcr:content/metadata/@custom:assetType = 'document' or jcr:content/metadata/@custom:assetType = 'image'))
and 
(
    not(jcr:content/@offtime) 
    or 
    (jcr:content/@offtime > xs:dateTime('2024-10-17T06:50:20.649Z'))
)
and 
(jcr:content/@cQ:lastReplicationAction_scene7 = 'Activate' and jcr:content/@cQ:lastReplicationAction = 'Activate')
]
order by jcr:content/@jcr:lastModified

 

Thanks

Avatar

Level 6

The xpath works correctly. But how do I do the same with querybuilder query.

Avatar

Community Advisor

You may try below query with minor (order) changed-

 

p.limit=-1
p.offset=0
path=/content/dam
type=dam:Asset

1_property=jcr:content/cq:lastReplicationAction_scene7
1_property.value=Activate

2_property=jcr:content/cq:lastReplicationAction
2_property.value=Activate

3_group.or=true

3_group.1_property=jcr:content/metadata/custom:assetType
3_group.1_property.1_value=image
3_group.1_property.2_value=document
3_group.1_property.1.operation=equals
3_group.1_property.2.operation=equals

4_group.or=true

4_group.1_property=jcr:content/offTime
4_group.1_property.operation=not

4_group.2_daterange.property=jcr:content/offTime
4_group.2_daterange.operation=>=
4_group.2_daterange.lowerBound=1729147820649

orderby.sort=asc
orderby=@jcr:content/jcr:lastModified

 

If above works then fine else you may check exist with exists operation as false

 

p.limit=-1
p.offset=0
path=/content/dam
type=dam:Asset

1_property=jcr:content/cq:lastReplicationAction_scene7
1_property.value=Activate

2_property=jcr:content/cq:lastReplicationAction
2_property.value=Activate

3_group.or=true

3_group.1_property=jcr:content/metadata/custom:assetType
3_group.1_property.1_value=image
3_group.1_property.2_value=document
3_group.1_property.1.operation=equals
3_group.1_property.2.operation=equals

4_group.or=true

4_group.1_property.operation=exists
4_group.1_property=jcr:content/offTime
4_group.1_property.value=false

4_group.2_daterange.property=jcr:content/offTime
4_group.2_daterange.operation=>=
4_group.2_daterange.lowerBound=1729147820649

orderby.sort=asc
orderby=@jcr:content/jcr:lastModified

 

 

Thanks

Avatar

Level 6

The first query returns in xpath as:

/jcr:root/content/dam//element(*, dam:Asset)
[
((jcr:content/metadata/@custom:assetType = 'document' or jcr:content/metadata/@custom:assetType = 'image'))
and (not(jcr:content/@offTime)
and (jcr:content/@offTime > xs:dateTime('2024-10-17T06:50:20.649Z')))
and (jcr:content/@cq:lastReplicationAction_scene7 = 'Activate' and jcr:content/@cq:lastReplicationAction = 'Activate')
]
order by jcr:content/@jcr:lastModified


And the second as,

/jcr:root/content/dam//element(*, dam:Asset)
[
((jcr:content/metadata/@custom:assetType = 'document' or jcr:content/metadata/@custom:assetType = 'image'))
and (not(jcr:content/@offTime)
and (jcr:content/@offTime > xs:dateTime('2024-10-17T06:50:20.649Z')))
and (jcr:content/@cq:lastReplicationAction_scene7 = 'Activate' and jcr:content/@cq:lastReplicationAction = 'Activate')
]
order by jcr:content/@jcr:lastModified


Please note that both are still AND condition.

Avatar

Correct answer by
Community Advisor

Hi @jezwn ,

Please try below one

p.limit=-1
p.offset=0
path=/content/dam
type=dam:Asset

1_property=jcr:content/cq:lastReplicationAction_scene7
1_property.value=Activate

2_property=jcr:content/cq:lastReplicationAction
2_property.value=Activate

3_group.p.or=true

3_group.1_property=jcr:content/metadata/custom:assetType
3_group.1_property.1_value=image
3_group.1_property.2_value=document
3_group.1_property.1.operation=equals
3_group.1_property.2.operation=equals

4_group.p.or=true

4_group.1_property.operation=exists
4_group.1_property=jcr:content/offTime
4_group.1_property.value=false

4_group.2_daterange.property=jcr:content/offTime
4_group.2_daterange.operation=>=
4_group.2_daterange.lowerBound=1729147820649

orderby.sort=asc
orderby=@jcr:content/jcr:lastModified

Use group.p.or=true instead of group.or=true

Thanks

Avatar

Level 6

That worked like a charm. Could you help me understand what difference does the p make? Thanks