Select to view content in your preferred language

How do handle Arcades' Count() and First() with an empty table?

744
1
04-28-2020 02:29 PM
TL2
by
Frequent Contributor

This script adds sequential values based on the last value.  My problem is I have to have at least one value already in place for First() to work, else it errors out.

Also when I try to add a Count() I get Array type expected error.

How do you properly code for:  AKA how do you check for empty table and if empty give it a value?

if count == 0  {return  something}

else do this

else do that

‍‍‍‍‍‍‍‍‍‍‍‍‍

This code below works great as long as there one record in the table with an assignednum.  If not it errors on line 3.  I tried to code with IIf & IsNaN/IsEmpty with no avail.  (Attribute Calculation Rule on Insert)

Thanks.

Xander Bakker

var sql = Concatenate("assignednum like", "'%", Year(Now()), "%'")
var fs = first(OrderBy(Filter(FeatureSetbyName($datastore, table), sql), 'assignednum DESC'))
var lastnum = Number(mid(fs.assignednum,11,4),'0000' )
var int = ++lastnum


if (number(mid(fs.assignednum,6,4)) == Year(Now())) {
return Concatenate("SUDOE ",Year(Now()),"-",text(int,'0000'),"RCI")
}

else if (number(mid(fs.assignednum,6,4)) != Year(Now())) {
return Concatenate("SUDOE ",Year(Now()),"-0001","RCI")
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (2)
0 Kudos
1 Reply
XanderBakker
Esri Esteemed Contributor

Hi T L ,

I have been seeing some questions that querying related information and obtaining 0 records is generating errors. I would probably go and test what it is you are getting back. It should be a FeatureSet, and when you apply first it shoud be a feature. Can you use TypeOf(fieldOrValue) in the console to check the result? 

Also it might be related to the type of data that you are working with. Can you provide more information about the table and the datastore used?

0 Kudos