Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How can I query numeric data of type String by condition?

Avatar

Level 3

Dears

       As shown, if the field is set to a number of type String, how can I query the data according to the condition?

ChaoXiong_2-1670318922902.png

ChaoXiong_6-1670319247180.png

ChaoXiong_7-1670319269960.png

 

ChaoXiong_3-1670318970267.png

 

ChaoXiong_4-1670319009250.pngChaoXiong_5-1670319021181.png

 

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi @ChaoXiong ,

 

You can try using groovy script which can read the value from String property and save in long property. This will help you manipulate the content and query the field with numeric operations.

 

Thanks,

Nikita Garg

View solution in original post

4 Replies

Avatar

Employee

@ChaoXiong 

If the Field is String Type, you cannot expect numeral comparison as an output for logical operators. In the end, it is being compared as a String and not a numeral.

 

I would suggest changing the Data Type of this "number" property to Long instead of String.

Avatar

Level 3

Thanks @krati_garg 

Because this is an example, there is already a lot of data in the actual project that is of String type, so I hope that there are related methods to query instead of modifying its type.

Avatar

Correct answer by
Employee

Hi @ChaoXiong ,

 

You can try using groovy script which can read the value from String property and save in long property. This will help you manipulate the content and query the field with numeric operations.

 

Thanks,

Nikita Garg

Avatar

Level 5

Hi @ChaoXiong 

 

1. Use SQL2 Query and Cast statement to convert datatypes. How to use AEM JCR SQL2 query strings to query for nodes in Java Content Repository - Sourced Code

 

2. If property storing number with minimal range e.g., maximum number is 13 then use OR operator for 13 times in query builder query (Ugly solution)

 

FYI: If you want to change the data type - How to Change Data Type in AEM or Data Typecast using @TypeHint (argildx.us)

 

Hope this helps.

 

Thanks,

Chandra