Select to view content in your preferred language

Invalid Where clause - Left function - Expression Builder - Arcade - Attribute Rule

799
17
Jump to solution
08-07-2024 07:38 AM
hw_mwf
by
Occasional Contributor

Trying to create an attribute rule (immediate calculation rule) on a feature class within an Enterprise Geodatabase in Oracle (.sde) within ArcGIS Pro 2.9.5. I want to filter to improve performance. Specifically, selecting only records when the first five characters of the UNITID text field equal the WINDEX text field. I am starting with the following two lines of Arcade code in the Expression Builder and when I click the green Verify check mark, its says 'Expression is valid'.

var cur_unitid = Filter(FeatureSetByName($datastore, "WSL", ['UNITID'], false), 'Left(UNITID, 5) == $feature.WINDEX');
var cur_unitid_desc = OrderBy(cur_unitid, 'UNITID DESC');

However, when I add the following third line of code and click the green Verify check mark, it says 'Invalid expression. Error on line 3. Invalid where clause (Left(UNITID, 5) == $feature.WINDEX)'.

var cur_unitid_max = first(cur_unitid_desc);

Can the Left function be used on a feature class field name and/or is there an error in how I am using it?

 

0 Kudos
1 Solution

Accepted Solutions
hw_mwf
by
Occasional Contributor

Agreed. The code works when the feature class is in a .gdb but not in a .sde. Specifically, the First function fails with a 'General evaluation error'. You did solve my initial problem (use a Substring function instead of Left), so I'll 'Accept as Solution' and repost this additional issue if I cannot figure it out. Thanks!

View solution in original post

0 Kudos
17 Replies
KenBuja
MVP Esteemed Contributor

Your sql expression is invalid, since it doesn't understand Arcade syntax (including variables such as $feature). You can only use SQL92 syntax. An expression like this should work

var value = $feature.WINDEX;
var cur_unitid = Filter(FeatureSetByName($datastore, "WSL", ['UNITID'], false), "Substring(UNITID, 1, 5) = @value");
var cur_unitid_desc = OrderBy(cur_unitid, 'UNITID DESC');
var cur_unitid_max = first(cur_unitid_desc);

 

0 Kudos
hw_mwf
by
Occasional Contributor

Thanks for the reply. The first 3 lines of your code yield 'Expression is valid', however the 4th line yields the error 'Invalid expression. Error on line 4. General evaluation error'.

0 Kudos
KenBuja
MVP Esteemed Contributor

Have you tried completing the rule, adding in what you want to return?

0 Kudos
hw_mwf
by
Occasional Contributor

I added the below as the 5th line, and the error remains (Error on line 4. General evaluation error).

return cur_unitid_max.UNITID;

0 Kudos
KenBuja
MVP Esteemed Contributor

What happens with this code? I know it's not giving the maximum record, but it's just testing out the filtered result.

var value = $feature.WINDEX;
var cur_unitid = Filter(FeatureSetByName($datastore, "WSL", ['UNITID'], false), "Substring(UNITID, 1, 5) = @value");
//var cur_unitid_desc = OrderBy(cur_unitid, 'UNITID DESC');
var cur_unitid_max = First(cur_unitid);
return cur_unitid_max.UNITID;

 

0 Kudos
hw_mwf
by
Occasional Contributor

Still the same error.

0 Kudos
KenBuja
MVP Esteemed Contributor

Let's check whether you're getting anything back from the Filter

var value = $feature.WINDEX;
var cur_unitid = Filter(FeatureSetByName($datastore, "WSL", ['UNITID'], false), "Substring(UNITID, 1, 5) = @value");
return Count(cur_unitid);
0 Kudos
hw_mwf
by
Occasional Contributor

This is now the error 'Invalid expression. Error on line 3. Failed to query statistics.

0 Kudos
KenBuja
MVP Esteemed Contributor

The testing I've done in the Playground using the example public portal item has worked correctly.

Snag_157b5bf.png

Are you sure you have the correct information for the FeatureSetByName function? What happens with this code?

var cur_unitid = FeatureSetByName($datastore, "WSL", ['UNITID'], false);
return Count(cur_unitid);
0 Kudos