Select to view content in your preferred language

Arcade Calculation Rule Increment Attribute Value

911
6
Jump to solution
08-16-2022 03:27 AM
Luca_Schikowski
New Contributor III

Hey guys,

I am working on an attribute rule for the devices in my utility network.

I have 2 different assetgroups: Adresses and distribution boxes. One distribution box is able to supply 96 units. So whenever a new adress is added, the user has to fill an attribute "Number" which contains the amount of units at this adress. This works fine so far.

The Distribution Box also has an Attribute called "Number_Apartments" which surprisingly contains the amount of units at this box. Here is where the fun begins. When an adress with for example 5 units is added (Attribute "Number" is 5), I want to increment the "Number_Apartments"-value automatically by 5. Sadly i can't get this done. 

Do you have any idea how to solve this?

Thanks in advance!

Luca

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
jclarke
New Contributor III

Hi Luca - it might be worth including a small diagram of how your addresses connect up to your distribution boxes. E.g. if they have junction-junction association then you may be able to use the Arcade functions specific to Utility Network like FeatureSetByAssociation

View solution in original post

6 Replies
JohannesLindner
MVP Frequent Contributor

That is absolutely possible. Question: How do you get the distribution box that belongs to an address? Do you have a foreign key field? Have you built a relationship class? Do you use spatial relationship?


Have a great day!
Johannes
Luca_Schikowski
New Contributor III

Hi, my Adresses got an attribute called "box" which contains the name of the distribution box. My boxes got an attribute "name" which contains the exact same values as "box". I am using a Filter which returns all boxes with the adresses box-name: 

var box_filtered = Filter(box_featuredataset, "name = @box")

Actually i never heard of Relationship Classes before. I will take a look at it. Your code is understandable and seems to do excactly what I want. I just need some time to get into relationships and will reply here if I have any more questions. 

Thank you very much for your quick reply!
Have a nice day
Luca

0 Kudos
Luca_Schikowski
New Contributor III

So i tried using a relationship class but it failed with error code 160263:

https://pro.arcgis.com/en/pro-app/2.9/tool-reference/tool-errors-and-warnings/160001-170000/tool-err...

I understand the usage of relationship classes but it seems that its not the way how I can solve this.

0 Kudos
JohannesLindner
MVP Frequent Contributor

Hmm... That seems like a very rare error. Either you used some wrong inputs or there's something funky with your data.

This is not the place to get into this, though. If you want to create relationship classes (they can be useful but are rarely (never?) really neccessary), I suggest asking for help in the Data Management - Esri Community

 

You can also just use the filter you already have in place, I updated the code in my other anser.


Have a great day!
Johannes
0 Kudos
JohannesLindner
MVP Frequent Contributor

 

// Calculation Attribute Rule on Addresses
// field: empty
// triggers: Insert, Update, Delete
// Exclude from application Evaluation

// if we're updating the address, but not changing the Number field, abort
if($editcontext.editType == "UPDATE" && $feature.Number == $originalfeature.Number) { return }

// get the related distribution box
var box_name = $feature.box
var box_featuredataset = FeatureSetByName(...)
var box = First(Filter(box_featuredataset, "name = @box_name"))
if(box == null) { return } // no related  box found, abort

// get the current Apartment count and calculate the new one, according to our edit mode:
// Insert: add
// Delete: subtract
// Update: subtract old, add new
var apartments = box.Number_Apartments
var change = When(
    $editcontext.editType == "INSERT", $feature.Number,
    $editcontext.editType == "DELETE", -$feature.Number,
    $editcontext.editType == "UPDATE", -$originalfeature.Number + $feature.Number,
    0 // default value
)

// instead of returning a value, we return a dictionary that follows certain rules, see
// https://pro.arcgis.com/en/pro-app/2.9/help/data/geodatabases/overview/attribute-rule-dictionary-keywords.htm
return {
    "edit": [{
        "className": "Addresses",
        "updates": [{
            "globalID": box.GlobalID,//or "objectID": box.OBJECTID
            "attributes": {"Number_Apartments": apartments + change}
        }]
    }]
}

 


Have a great day!
Johannes
0 Kudos
jclarke
New Contributor III

Hi Luca - it might be worth including a small diagram of how your addresses connect up to your distribution boxes. E.g. if they have junction-junction association then you may be able to use the Arcade functions specific to Utility Network like FeatureSetByAssociation