Select to view content in your preferred language

Arcade expression error - sequential number generator

504
11
Jump to solution
06-27-2024 09:32 AM
dsinha
by
New Contributor III

Hello,

I am trying to use the expression mentioned on this page to generate the next number in a field that stores the record number of observations collected in the field. The field idlong is an integer field and is located in the hosted feature layer DataCollectionInspection.

Here is my version of the arcade expression:

var numberlist = FeatureSetByName($map,"DataCollectionInspection")
var topnum = Top(OrderBy(numberlist,'<idlong DESC'),1)
var counter = Number(Max(topnum,'idlong'))
var id = counter+1

return id
 
When I run it in the Arcade Editor, I get the following error message: Test execution error: Unknown Error. Verify test data.
 
Would anyone know what I am doing wrong?
 
Thanks!
 
Deb.
0 Kudos
3 Solutions

Accepted Solutions
ChrisDunn1
Esri Contributor

Hi @dsinha ,

It loos like you just have a typo on the second line.

Right now your expression says '<idlong DESC', but it should just be 'idlong DESC'. The opening bracket looks like it was copied from the example but wasn't deleted.

Hope that helps!

Chris

View solution in original post

HawjinF
Esri Contributor

Hi,

I noticed a typo in this line of code:

var topnum = Top(OrderBy(numberlist,'<idlong DESC'),1)

It should be:

var topnum = Top(OrderBy(numberlist,'idlong DESC'),1)

I hope this works.

View solution in original post

ChrisDunn1
Esri Contributor

Sure thing - I think you could do it two ways:

var numberlist = $layer

If you use that for the first line instead of the feature set expression, the rest of the code should work the same.

I believe you could remove the first line and instead go right to:

var topnum = Top(OrderBy($layer,'idlong DESC'),1)

I haven't tested that though.

View solution in original post

11 Replies
ChrisDunn1
Esri Contributor

Hi @dsinha ,

It loos like you just have a typo on the second line.

Right now your expression says '<idlong DESC', but it should just be 'idlong DESC'. The opening bracket looks like it was copied from the example but wasn't deleted.

Hope that helps!

Chris

HawjinF
Esri Contributor

Hi,

I noticed a typo in this line of code:

var topnum = Top(OrderBy(numberlist,'<idlong DESC'),1)

It should be:

var topnum = Top(OrderBy(numberlist,'idlong DESC'),1)

I hope this works.

dsinha
by
New Contributor III

Thank you so much! Completely missed that bracket 😊

0 Kudos
dsinha
by
New Contributor III

I have a follow-up question: Does this Arcade expression (and Arcade expressions in general) work in the offline mode?

0 Kudos
ChrisDunn1
Esri Contributor

Hi @dsinha - in general most Arcade expressions will work offline, but there are a few exceptions. Anything that sends a request to the server will not work, so something like featureSetByPortalItem would not work. In this case, I believe calling the feature set by name within the map will work, however it will only query features that are within the offline area. If you are not taking the entire feature set offline with your offline area then the results from this query may not be accurate.

It is also worth noting that if you have multiple people working with offline areas they would end up creating duplicate unique identifiers which would likely cause some data problems down the line, depending on your workflow.

0 Kudos
dsinha
by
New Contributor III

Thanks for your reply @ChrisDunn1. I did take the entire feature set offline, but it is not autogenerating the number.

0 Kudos
ChrisDunn1
Esri Contributor

I may have been mistaken - it might be that all FeatureSet functions do not work offline, however $layer might work to access the IDs instead of FeatureSetByName, that would be worth trying.

0 Kudos
dsinha
by
New Contributor III

Sorry @ChrisDunn1, I am not well-versed in Arcade. Could you suggest how the expression would read with $layer instead of FeatureSetByName? I am assuming its just the first line. Thanks for your help!

0 Kudos
ChrisDunn1
Esri Contributor

Sure thing - I think you could do it two ways:

var numberlist = $layer

If you use that for the first line instead of the feature set expression, the rest of the code should work the same.

I believe you could remove the first line and instead go right to:

var topnum = Top(OrderBy($layer,'idlong DESC'),1)

I haven't tested that though.