Select to view content in your preferred language

Using data expression to filter feature set for display in list

185
2
Jump to solution
a month ago
Labels (1)
sophered
New Contributor III

Hello! I am trying to filter a featureset to only show features that contain carriage returns within a list element. 

Here is what I have so far, which currently works in test BUT does not allow me to select within data expressions:

var portal = Portal('portal url')
var fs = FeatureSetByPortalItem(portal, "itemid", 0, ['STREETNAME'],false)
var carriageReturnPosition = Find("\r", fs);
if (carriageReturnPosition != -1) {
return Filter(fs, carriageReturnPosition)
} else {
return null
}

The error that I am getting is 'Unable to execute Arcade Script". What am I doing wrong? Is it possible to accomplish this?

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

For a Data Expression, you need to return a FeatureSet, no matter what. It's fine to return the result of the Filter function, even if there are no matching features. Also, the Filter expression takes a SQL statement, not an Arcade variable. Try something like this:

 

var portal = Portal('portal url')
var fs = FeatureSetByPortalItem(portal, "itemid", 0, ['STREETNAME'],false)

return Filter(fs, "STREETNAME LIKE '%\r%'")

 

That should filter to the features where the field has a return somewhere in them. Not sure how your database will like that, though. You may need to use a function to specify the carriage return character.

'%'+char(13)+'%' or name like '%'+char(10)+'%'

 

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
sophered
New Contributor III
var portal = Portal('portal url')
var fs = FeatureSetByPortalItem(portal, "itemid", 0, ['STREETNAME'],false)
var carriageReturnPosition = Find("\r", fs);
if (carriageReturnPosition != -1) {
return Filter(fs, carriageReturnPosition)
} else {
return null
}
0 Kudos
jcarlson
MVP Esteemed Contributor

For a Data Expression, you need to return a FeatureSet, no matter what. It's fine to return the result of the Filter function, even if there are no matching features. Also, the Filter expression takes a SQL statement, not an Arcade variable. Try something like this:

 

var portal = Portal('portal url')
var fs = FeatureSetByPortalItem(portal, "itemid", 0, ['STREETNAME'],false)

return Filter(fs, "STREETNAME LIKE '%\r%'")

 

That should filter to the features where the field has a return somewhere in them. Not sure how your database will like that, though. You may need to use a function to specify the carriage return character.

'%'+char(13)+'%' or name like '%'+char(10)+'%'

 

- Josh Carlson
Kendall County GIS