Hi,
This is my system configuration:
ArcGIS Pro 2.8
Electric Utility Network Version 4
ArcGIS Enterprise 10.8.1
SQL Server 2017
I'm trying to create a junction-junction connectivity association between a feature (with terminals) of the ElectricDevice class and another of the ElectricJunction class using attribute rules. I've searched the documentation (https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/attribute-rule-dictionary-keywords.htm) and followed some examples (https://github.com/Esri/arcade-expressions/blob/master/attribute_rule_calculation/CreateAttachmentAssociationByProximity.md and https://github.com/Esri/arcade-expressions/blob/master/attribute_rule_calculation
/CreateAssociation.md ) in the arcade-expressions github repo; but my rule is not creating the association.
The rule is triggered when a feature (Riser with AssetType = 103) from the ElectricJunction class is inserted, then the rule look for a feature (Fuse with AssetType = 565) from the ElectricDevice class to create a connectivity association with the terminal "SS:S2" of the Fuse. If there is not Fuse near the Riser then the rule search for a feature (Line End with AssetType = 100) from the ElectricJunction class an creates connectivity association between the Riser and the Line End instead.
Here are the 2 versions of the code that I've tested:
// Assigned To: ElectricJunction
// Name: Proximity_Connectivity_Association
// Description: Upon insertion of an ElectricJunction of the allowed AssetTypes
// creates the connectivity association to the closest ElectricDevice MV Fuse or
// MV ElectricJunction Line End
// Subtypes: All
// Field: notes
// Execute: Insert
// Exclude from application evaluation: True
// ************* User Variables *************
// This section has the functions and variables that need to be adjusted based on your implementation
// The field the rule is assigned to
var field_value = $feature.notes;
var association_class = null;
var search_distance = 100;
var search_unit = 'feet';
var feat_globalid = $feature.globalID;
var valid_asset_types = [103];
// ************* End User Variables Section *************
if (indexof(valid_asset_types, $feature.assettype) == -1) {
return field_value;
}
//Find the closest MV Fuse
var fsDevices = FeatureSetByName($datastore, 'UN_MODEL_V34.MODEL_V34.ElectricDevice',["GLOBALID"], true)
var fBuffer = Buffer(Geometry($feature), search_distance, search_unit)
var fsClosest = Intersects(fsDevices, fBuffer)
var fsFuses = Filter(fsClosest, 'ASSETTYPE = 565') //565 = MV Fuse\Overhead Cutout Fused Load Break
var minDistance = Infinity
if (Count(fsFuses) <= 0) {
var fsElecJunction = FeatureSetByName($datastore, 'UN_MODEL_V34.MODEL_V34.ElectricJunction',["GLOBALID"], true)
fsClosest = Intersects(fsElecJunction, fBuffer)
var fsLineEnd = Filter(fsClosest, 'ASSETTYPE = 100') //100 = MV Line End\Overhead Line End
if (Count(fsLineEnd) <= 0) {
return field_value
} else {
association_class = 'UN_MODEL_V34.MODEL_V34.ElectricJunction'
var closestle = null // closest MV Line End feature
for (var p in fsLineEnd) {
var pDistance = Distance(p, $feature, 'feet')
if (pDistance < minDistance) {
minDistance = pDistance;
closestle = p
}
}
}
} else {
association_class = 'UN_MODEL_V34.MODEL_V34.ElectricDevice'
var closestf = null // closest MV Fuse feature
for (var p in fsfuses) {
var pDistance = Distance(p, $feature, 'feet')
if (pDistance < minDistance) {
minDistance = pDistance;
closestf = p
}
}
}
if (!IsEmpty(closestf)) {
var assocation_update = [{'globalID': closestf.globalID, 'fromTerminal': 'SS:S2' ,'associationType': 'connected'}];
} else if (!IsEmpty(closestle)) {
var assocation_update = [{'globalID': closestle.globalID, 'associationType': 'connected'}];
}else {
return field_value;
}
var edit_payload = [{'className': association_class, 'updates': assocation_update}];
return {
"result": field_value,
"edit": edit_payload
};
// *************************************************************************************************************************
// Assigned To: ElectricJunction
// Name: Proximity_Connectivity_Association
// Description: Upon insertion of an ElectricJunction of the allowed AssetTypes
// creates the connectivity association to the closest ElectricDevice MV Fuse or
// MV ElectricJunction Line End
// Subtypes: All
// Field: notes
// Execute: Insert
// Exclude from application evaluation: True
// ************* User Variables *************
// This section has the functions and variables that need to be adjusted based on your implementation
// The field the rule is assigned to
var field_value = $feature.notes;
var association_class = null;
var search_distance = 100;
var search_unit = 'feet';
var feat_globalid = $feature.globalID;
var valid_asset_types = [103];
// ************* End User Variables Section *************
if (indexof(valid_asset_types, $feature.assettype) == -1) {
return field_value;
}
//Find the closest MV Fuse
var fsDevices = FeatureSetByName($datastore, 'UN_MODEL_V34.MODEL_V34.ElectricDevice',["GLOBALID"], true)
var fBuffer = Buffer(Geometry($feature), search_distance, search_unit)
var fsClosest = Intersects(fsDevices, fBuffer)
var fsFuses = Filter(fsClosest, 'ASSETTYPE = 565') //565 = MV Fuse\Overhead Cutout Fused Load Break
var minDistance = Infinity
if (Count(fsFuses) <= 0) {
var fsElecJunction = FeatureSetByName($datastore, 'UN_MODEL_V34.MODEL_V34.ElectricJunction',["GLOBALID"], true)
fsClosest = Intersects(fsElecJunction, fBuffer)
var fsLineEnd = Filter(fsClosest, 'ASSETTYPE = 100') //100 = MV Line End\Overhead Line End
if (Count(fsLineEnd) <= 0) {
return field_value
} else {
association_class = 'UN_MODEL_V34.MODEL_V34.ElectricJunction'
var closestle = null // closest MV Line End feature
for (var p in fsLineEnd) {
var pDistance = Distance(p, $feature, 'feet')
if (pDistance < minDistance) {
minDistance = pDistance;
closestle = p
}
}
}
} else {
association_class = 'UN_MODEL_V34.MODEL_V34.ElectricDevice'
var closestf = null // closest MV Fuse feature
for (var p in fsfuses) {
var pDistance = Distance(p, $feature, 'feet')
if (pDistance < minDistance) {
minDistance = pDistance;
closestf = p
}
}
}
if (!IsEmpty(closestf)) {
var association_update = [{
'fromnetworksourceid': 'UN_MODEL_V34.MODEL_V34.ElectricDevice',
'fromglobalid': closestf.globalID,
'fromterminalid': 1,
'tonetworksourceid': 'UN_MODEL_V34.MODEL_V34.ElectricJunction',
'toglobalid': $feature['globalid'],
'toterminalid': 1,
'associationtype': 1,
'iscontentvisible': 0,
'globalid': Guid()
}
]
} else if (!IsEmpty(closestle)) {
var assocation_update = [{'globalID': closestle.globalID, 'associationType': 'connected'}];
}else {
return field_value;
}
var edit_payload = [{'className': association_class, 'adds': assocation_update}];
return {
"result": field_value,
"edit": edit_payload
};