Select to view content in your preferred language

Adding Multiple Related Records based on Feature Drawn

166
3
4 weeks ago
ColeDagerhardt
New Contributor

I am developing a file geodatabase to document a fiber network. I am struggling to write an attribute rule that I think should be possible. This rule will interface between a feature class "CommCable" that represents fiber cable of various fiber counts and a geodatabase table "AllocationTable" that will have a row for each fiber strand. There is currently a relationship class set up between these two with the primary key being "CableID" from the feature class and the foreign key being "CableID" from the geodatabase table.

Here are the attributes I am using that are associated with both the feature class and the geodatabase table:

CommCable

  • CableID
  • StrandCount

AllocationTable  

  • CableID
  • StrandCount
  • StrandOrder

I am trying to write an attribute rule that whenever I draw in a feature within the "CommCable" feature class, the same number of rows are added to the "AllocationTable" as were defined in the "StrandCount" field within the feature class.

I would also like to populate all of those newly added rows with the "CableID" from the feature class (to the "CableID" of the "AllocationTable") and the "StrandCount" in the feature class (to the "StrandCount" of the "AllocationTable").

I am also trying to populate the “StrandOrder” field in the “AllocationTable” to populate sequentially (example: when drawing a 24 fiber cable, the 24 rows that are added will start at 1 and end at 24 for the “StrandOrder” field).

Below is the code I have so far. It currently adds the correct number of rows to the “AllocationTable”, however it does not populate any data.

// Get the CableID and StrandCount from the newly inserted feature
var cableID = $feature.CableID;
var strandCount = $feature.StrandCount;


// Create an array to hold the new rows for AllocationTable
var allocationRows = [];

// Loop through the number of strands and create a new row for each strand
for (var i = 1; i <= strandCount; i++) {
    var newRow = {
        'CableID': cableID,
        'StrandCount': strandCount,
        'StrandOrder': i
    };
    Push(allocationRows, newRow);
}

// Insert the new rows into the AllocationTable
return {
    'edit': [{
        'className': 'AllocationTable',
        'adds': allocationRows
    }]
};
0 Kudos
3 Replies
MikeMillerGIS
Esri Frequent Contributor

Take a look at this rule, should do exactly what you want.  Just remove the UN association stuff if you are not using a utility network.

https://github.com/Esri/arcade-expressions/blob/master/Industry/Communications/Calculation/Line-Crea...

0 Kudos
ColeDagerhardt
New Contributor

Thanks for that! I'm still a beginner at writing attribute rules, but I'm having trouble translating some of those functions and concepts to my specific file geodatabase. I am struggling to understand why the code I posted does not actually put the attribute data in the related table. 

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Looks like you definition of the row is invalid.

 

needs to be like this:

attributes = {
            'AssetGroup': strands_AG,
            'AssetType': strands_AT,
            'StrandID': strand_index,
            'TubeID': tube_index,
            'IsSpatial': 0,
            'NetworkLevel': network_level,
            'StrandStatus': strand_status_avail
        };
        line_adds[Count(line_adds)] = {
            'attributes': attributes,
            'geometry': Polyline(strand_shape),
            'associationType': 'content'
        };
0 Kudos