Skip to main content
16-Pearl
July 12, 2018
Solved

How use set wildcard characters [? % *] as target character in ThingWorx Query with "Like" filter?

  • July 12, 2018
  • 3 replies
  • 2356 views

There is a DataTable as below. How to get rows containing "%" ?

ID Value
1
%1
2
2?
3
*
4
+1

 

In above case, should be the 1st row.

Because % is a wildcard in Thing Query, how should I escape it?

Same question for ? and *.

Best answer by mneumann

Try the following code to just return the "%1" line

 

 

var query = {
 "filters": {
 "fieldName": "value",
 "type": "LIKE",
 "value": "\\u0025" + "1"
 }
};

var params = {
	query: query /* QUERY */
};

// result: INFOTABLE dataShape: "undefined"
var result = me.QueryDataTableEntries(params);

 

The % is unescaped into \\u0025 to reflect the hex number of the character

https://www.ascii.cl/htmlcodes.htm

 

For me it returned only this one row out of

 

%1
2?
*
+1
11
12
21
22

3 replies

mneumann16-PearlAnswer
16-Pearl
July 12, 2018

Try the following code to just return the "%1" line

 

 

var query = {
 "filters": {
 "fieldName": "value",
 "type": "LIKE",
 "value": "\\u0025" + "1"
 }
};

var params = {
	query: query /* QUERY */
};

// result: INFOTABLE dataShape: "undefined"
var result = me.QueryDataTableEntries(params);

 

The % is unescaped into \\u0025 to reflect the hex number of the character

https://www.ascii.cl/htmlcodes.htm

 

For me it returned only this one row out of

 

%1
2?
*
+1
11
12
21
22

wcui16-PearlAuthor
16-Pearl
July 13, 2018
wcui16-PearlAuthor
16-Pearl
July 13, 2018

The Unicode marking method also works for below characters. It should be a common way for all characters.

# $ ^