Select to view content in your preferred language

'Unexpected Null' error in Attribute Rule Validation

1309
2
Jump to solution
06-13-2023 01:44 PM
GregoryWhitaker
New Contributor II

Hello,

I'm currently building an immediate calculation (update) attribute rule in ArcGIS Pro (2.9x) that basically copies the updated row to a different feature class and adds a few attributes to the copied row from various other tables in the $datastore. I'm still somewhat new to arcade.

One of the table values that I need to grab and insert is not guaranteed to be populated, so I have accounted for this by using an IsEmpty condition before setting the field values to a variable. 

The issue I'm having is that, the arcade editor box will not allow me to save and apply the code because the random(?) row that it's pulling to do the syntax validation had a null value before I added the null check. I added a conditional null check afterwards realizing that I had forgotten to do so, but it still does the same. As a last resort, just to get the rule saved, I calculated out any null values in the field of concern, also to no avail. It almost seems like pro is caching values somewhere or the validation is stuck, but I've cleared the project cache, created a new project, and re-added all the layers, so I don't think that is it.

Code is below. The offender is ggsFilter.GGS . I have also tried == null as well as the DefaultValue() commented out below it. Also probably worth noting that all the field values are coming in with the ggsFilter, so it's not that there's an empty object.

Any pointers or ideas would be greatly appreciated! Thanks in advance!  

Capture.PNG

 

var geom = Geometry($feature);

//COMPANY TABLE
var companyFc = FeatureSetByName($datastore, "COMPANY", ["UNIQUE_ID", "COMPANY_NAME", "IS_OPERATOR"], false);
var companyFilter = First(Filter(companyFc, "UNIQUE_ID = '" + $feature.COMPANY_ID + "'"));

//GGS_DISTRICT
var ggsFc = FeatureSetByName($datastore, "PODS_GGS_DISTRICT", ["UNIQUE_ID", "STANDARD_NAME", "GGS", "FIELD_OFFICE"], false);
var ggsFilter = First(Filter(ggsFc, "UNIQUE_ID = '" + $feature.GGS_DISTRICT_ID + "'"));

if (IsEmpty(ggsFilter.GGS)) {
    var ggsName = 'GGS data is null';
    var ggsNumber = 'GGS data is null';
} else {
    var ggsText = Split(Trim(ggsFilter.GGS), ' - ');
    var ggsName = ggsText[0];
    var ggsNumber = ggsText[1];
}
// var ggsName = DefaultValue(Split(Trim(ggsFilter.GGS), ' - ')[0], 'GGS data is null');
// var ggsNumber = DefaultValue(Split(Trim(ggsFilter.GGS), ' - ')[1], 'GGS data is null');

//OPERATING_AREA
var operatingAreaFc = FeatureSetByName($datastore, "PODS_OPERATING_AREA", ["STANDARD_NAME"]);
var operatingAreaIntersect = First(Intersects(operatingAreaFc, geom));

//OPERATING_GROUP
var operatingGroupFc = FeatureSetByName($datastore, "PODS_OPERATING_GROUP", ["STANDARD_NAME"]);
var operatingGroupIntersect = First(Intersects(operatingGroupFc, geom));

//FRANCHISE
var franchiseFc = FeatureSetByName($datastore, "PODS_FRANCHISE", ["STANDARD_NAME"]);
var franchiseIntersect = First(Intersects(franchiseFc, geom));

//DIVISION
var divisionFc = FeatureSetByName($datastore, "PODS_DIVISION", ["STANDARD_NAME"]);
var divisionIntersect = First(Intersects(divisionFc, geom));

if ($feature.EDIT_RESPONSE == 'Abandon') {
    var fieldMap = [
        { 
            "attributes": {
                //from StructureBoundary
                "COMMENTS": $feature.COMMENTS,
                "DESCRIPTION": $feature.DESCRIPTION,
                "SUBTYPE": $feature.SUBTYPE,
                "UNIQUE_TERM_ID": $feature.UNIQUE_TERM_ID,
                "SITE_NAME": $feature.SITE_NAME,
                "SITE_ID": $feature.SITE_ID,
                "BOUNDARY_TYPE": $feature.BOUNDARY_TYPE,
                "SOURCE": $feature.SOURCE,
                "NAME": $feature.NAME,
                "UNIQUE_ID": $feature.UNIQUE_ID,
                "WORKORDER": $feature.WORKORDER,
                "ACREAGE": $feature.ACREAGE,
                "COUNTY": $feature.COUNTY,
                "TRANSMISSION_FACILITY": $feature.TRANSMISSION_FACILITY,
                "HCA_DIAMETER": $feature.HCA_DIAMETER,
                "HCA_FACILITY": $feature.HCA_FACILITY,
                "BORN_ON_DATE": $feature.BORN_ON_DATE,
                "PROGRAM_NAME": $feature.PROGRAM_NAME,
                "PROJECT_NAME": $feature.PROJECT_NAME,
                "FERC_REGULATED": $feature.FERC_REGULATED,
                "OPERATOR_ID": $feature.OPERATOR_ID,
                "HCA_TYPE": $feature.HCA_TYPE,
                "PHYSICAL_STATE": $feature.STATE,
                //from COMPANY
                "COMPANY_NAME": companyFilter.COMPANY_NAME,
                "OPERATOR": companyFilter.IS_OPERATOR,
                //from OPERATING_AREA
                "OPERATING_AREA": operatingAreaIntersect.STANDARD_NAME,
                //from OPERATING_GROUP
                "OPERATING_GROUP": operatingGroupIntersect.STANDARD_NAME,
                //from FRANCHISE
                "FRANCHISE": franchiseIntersect.STANDARD_NAME,
                //from DIVISION
                "DIVISION": divisionIntersect.STANDARD_NAME,
                //from GGS_DISTRICT
                "DISTRICT_GGS": ggsFilter.STANDARD_NAME,
                "GGS_NAME": DefaultValue(Split(Trim(ggsFilter.GGS), ' - ')[0], 'GGS data is null'),
                "GGS_NUMBER": DefaultValue(Split(Trim(ggsFilter.GGS), ' - ')[1], 'GGS data is null'),
                "FIELD_OFFICE": ggsFilter.FIELD_OFFICE
            },
            "geometry": geom
        }
    ]

    return {
        "edit": [{
            "className": "Site_Abandoned",
            "adds": fieldMap
        }]  
    }
}
else if ($feature.EDIT_RESPONSE == 'Divest') {
    //TODO LATER
    var fieldMap = [
        { 
            "attributes": {
                "COMMENTS": $feature.COMMENTS,
                "DESCRIPTION": $feature.DESCRIPTION,
                "SUBTYPE": $feature.SUBTYPE,
                "UNIQUE_TERM_ID": $feature.UNIQUE_TERM_ID,
                "SITE_NAME": $feature.SITE_NAME,
                "SITE_ID": $feature.SITE_ID,
                "BOUNDARY_TYPE": $feature.BOUNDARY_TYPE,
                "SOURCE": $feature.SOURCE,
                "NAME": $feature.NAME,
                "UNIQUE_ID": $feature.UNIQUE_ID,
                "WORKORDER": $feature.WORKORDER,
                "ACREAGE": $feature.ACREAGE,
                "COUNTY": $feature.COUNTY,
                "OPERATIONAL_STATUS": $feature.OPERATIONAL_STATUS,
                "TRANSMISSION_FACILITY": $feature.TRANSMISSION_FACILITY,
                "HCA_DIAMETER": $feature.HCA_DIAMETER,
                "HCA_FACILITY": $feature.HCA_FACILITY,
                "BORN_ON_DATE": $feature.BORN_ON_DATE,
                "PROGRAM_NAME": $feature.PROGRAM_NAME,
                "PROJECT_NAME": $feature.PROJECT_NAME,
                "FERC_REGULATED": $feature.FERC_REGULATED,
                "OPERATOR_ID": $feature.OPERATOR_ID,
                "HCA_TYPE": $feature.HCA_TYPE,
                "PHYSICAL_STATE": $feature.STATE,

                "COMPANY_NAME": companyName,
                "OPERATOR": operator
            },
            "geometry": geom
        }
    ]

    return {
        "edit": [{
            "className": "Site_Divested",
            "adds": fieldMap
        }]  
    }
}

 

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

When you call First() on an empty Featureset, it will return null. You're trying to call an attribute of null, which raises the error.

 

if (IsEmpty(ggsFilter) || IsEmpty(ggsFilter.GGS)) {
//...
}

 

 

You're missing null checks in your return dictionaries, too. These might pass evaluation, but they will raise errors on execution if you encounter empty filtered Featuresets. An easy way to handle these would be IIf():

 

if ($feature.EDIT_RESPONSE == 'Abandon') {
    var fieldMap = [
        { 
            "attributes": {
                //from StructureBoundary
                    // bla
                //from COMPANY
                "COMPANY_NAME": IIf(companyFilter == null, "Default Value", .COMPANY_NAME),
                "OPERATOR": IIf(companyFilter == null, "Default Value", companyFilter.IS_OPERATOR),

 


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

When you call First() on an empty Featureset, it will return null. You're trying to call an attribute of null, which raises the error.

 

if (IsEmpty(ggsFilter) || IsEmpty(ggsFilter.GGS)) {
//...
}

 

 

You're missing null checks in your return dictionaries, too. These might pass evaluation, but they will raise errors on execution if you encounter empty filtered Featuresets. An easy way to handle these would be IIf():

 

if ($feature.EDIT_RESPONSE == 'Abandon') {
    var fieldMap = [
        { 
            "attributes": {
                //from StructureBoundary
                    // bla
                //from COMPANY
                "COMPANY_NAME": IIf(companyFilter == null, "Default Value", .COMPANY_NAME),
                "OPERATOR": IIf(companyFilter == null, "Default Value", companyFilter.IS_OPERATOR),

 


Have a great day!
Johannes
GregoryWhitaker
New Contributor II

Hey, that worked. Thank you @JohannesLindner for the help!!

I now see how that error was happening--I had forgotten to account for the sample validation record not having a match and therefore returning an empty filter. I didn't think to check the filter itself as well as the field value.

Best,

-Greg

0 Kudos