UN Attribute Rules Expression Builder Arcade

152
2
Jump to solution
06-02-2022 05:59 AM
FynnScharpen
New Contributor III

Good evening, 

today I'll tried to set up my first attribute rule in my very first Utility Network but I never worked with Arcade before so I had problems doing so.

My topic is glassfiber so I tried to set up a rule for my adresses which have a field called main provider. There are 4 different main providers atm. I wanna count the amount of adresses with the same main provider and if there are more than 25 adresses on one i would like to get a error message. Is someone able to help me? Or someone knows how to imrpove in Arcade fast...with a free course or so. The only thing I found is how to count the amount of points in a shapfile but I would like to keep it attribute based. 

Kind Regards from Germany

 

Fynn Scharpen 🙂

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Regular Contributor

For what you want to do, this would be a starting point:

// load all addresses
var addresses = FeatureSetByName($datastore, "AddressTableName", ["MainProvider"], false)

// filter the addresses for the main provider of the active feature
var provider = $feature.MainProvider
var filtered_addresses = Filter(addresses, "MainProvider = @provider")

// count and return error message
if(Count(filtered_addresses) > 25) {
    return {"errorMessage": "A provider can't supply more than 25 addresses!"}
}

// if we land here, the provider has <= 25 addresses
// rest of your code

Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Regular Contributor

For getting started:

Getting Started | ArcGIS Arcade | ArcGIS Developer

Your Arcade Questions Answered (esri.com)

Attribute Rules in Arcade (From Scratch) - Demo Th... - Esri Community

Introduction to Attribute Rules

 

Useful documentation (I have this bookmarked):

Function Reference | ArcGIS Arcade | ArcGIS Developer

 

Code examples:

GitHub - Esri/arcade-expressions: ArcGIS Arcade expression templates for all supported profiles in t...

 

Some videos:

Attribute Rules Videos - Esri Community

 

And of course the Attribute Rules - Esri Community for asking all of your questions about Attribute Rules.

Sadly, there's no group for general Arcade yet; the jury is out on whether to post those in the ArcGIS Pro group or the AGOL group...


Have a great day!
Johannes
JohannesLindner
MVP Regular Contributor

For what you want to do, this would be a starting point:

// load all addresses
var addresses = FeatureSetByName($datastore, "AddressTableName", ["MainProvider"], false)

// filter the addresses for the main provider of the active feature
var provider = $feature.MainProvider
var filtered_addresses = Filter(addresses, "MainProvider = @provider")

// count and return error message
if(Count(filtered_addresses) > 25) {
    return {"errorMessage": "A provider can't supply more than 25 addresses!"}
}

// if we land here, the provider has <= 25 addresses
// rest of your code

Have a great day!
Johannes