Select to view content in your preferred language

Attribute rule not updating field

256
0
02-15-2024 02:25 AM
ChristyRhodes
New Contributor

Hello,

I have a 1:M relationship class which tracks inspections of grass cutting for a grass verges, I have created an attribute rule 2 ways which aim's to update a field called 'cutNumber' which is currently set as '0'. 

var asset = FeatureSetByRelationshipName($feature, "Grass_Inspections_REL", ['cutNumber'], true);

var asset = First(asset);

if (!IsEmpty(asset)) {

    if ($feature.inspCutStatus == 'Cut'){

        asset['cutNumber'] = asset['cutNumber'] + 1;

        return asset['cutNumber'];

    } else {

        return asset['cutNumber'];

    }

This is the first script which has no error messages but the 'cutNumber' field doesn't update by increments of +1 when an inspections has a cut Status == 'Cut'.  

I then tried this way 

// Get the related inspections

var inspections = FeatureSetByRelationshipName($feature, "Grass_Inspections_REL", ['cutStatus', 'cutDate'], true);

Filter(inspections, 'cutStatus = inspCutStatus')

// Initialize the count of cut inspections

var cutCount = 0;

 

// Loop through the inspections

for (var inspection in inspections) {

    // Check if the cutStatus is 'Cut' and the cutDate is in 2024

    if (inspection['cutStatus'] == 'Cut' && Year(inspection['cutDate']) == 2024){

        // Increment the count

    cutCount += 1;

}

}

 

// Update the 'cutNumber' field with the count of cut inspections

$feature.inspCutNumber == cutCount;

Which returns Null instead. 

 

// Return the updated feature

return $feature.inspCutNumber.

This return a Null instead of '0' like the previous example.  

Any ideas why this might be the case ?

Tags (1)
0 Kudos
0 Replies