How to change attribute value with dictonary keywords

132
4
12-07-2022 03:51 AM
PeterStampfl
New Contributor II

Hi,

I have this script where I tried to modify an association and an attribute value. The modification of the association works, but I can not change the attribute value of the created feature. (See first script)

If I trie to modify an attribute value of another feature (not the creaded on) it works. (See second script)

I tried also to change only to attribute value, without modifying the association. It did also not work out. (See third script)

Changes in the script are only made within the return statement.

 

First script:

// MV Connector Line (Verbindingskabel) whithout Containment -> MV Substation
if (($feature.assetgroup == 929 && $feature.ASSET_NUMBER == "associate")) {
var update_class = 'ElectricLine'
var update_class_asso = 'ElectricAssembly'
var filterAssembly = "ASSETGROUP = 904"

var boundaries = FeatureSetByName($datastore, "FLUVIUS_1091_DESIGN.UTROOT.StructureBoundary", ["globalid"], true);
if(isempty(boundaries)){
return;
//{"errorMessage": "Error 1"};
};

var intersectBoundaries = Intersects(boundaries, $feature);
if(isempty(intersectBoundaries)){
return;
//{"errorMessage": "Error 2"};
};

var structureBoundary = First(intersectBoundaries);
if(isempty(structureBoundary)){
return;
//{"errorMessage": "Error 3"};
}

var AllAssemblys = FeatureSetByName($datastore, "FLUVIUS_1091_DESIGN.UTROOT.ElectricAssembly", ["assetgroup", "globalid"], true);
if(isempty(AllAssemblys)){
return;
//{"errorMessage": "Error 4"};
}

var XYassembly = Filter(AllAssemblys, filterAssembly)
if(isempty(XYassembly)){
return;
//{"errorMessage": "Error 5"};
};

var intersectAssembly = Intersects(XYassembly, structureBoundary);
if(isempty(intersectBoundaries)){
return;
//{"errorMessage": "Error 6"};
};

var assemblyGeo = First(intersectAssembly)
if(isempty(assemblyGeo)){
return;
//{"errorMessage": "Error 7"};
}


return {
"edit":[{
"className": update_class_asso,
"updates":[{
"globalid": assemblyGeo.globalid,
"associationType":"container"
}]
}, {
"className": update_class,
'updates': [{
'globalID': $feature.globalid,
'attributes': {
'ASSET_NUMBER': "Test"
}
}]
}]
}
}

 

Second Script:


// MV Connector Line (Verbindingskabel) whithout Containment -> MV Substation
if (($feature.assetgroup == 929 && $feature.ASSET_NUMBER == "associate")) {
var update_class = 'ElectricLine'
var update_class_asso = 'ElectricAssembly'
var filterAssembly = "ASSETGROUP = 904"

var boundaries = FeatureSetByName($datastore, "FLUVIUS_1091_DESIGN.UTROOT.StructureBoundary", ["globalid"], true);
if(isempty(boundaries)){
return;
//{"errorMessage": "Error 1"};
};

var intersectBoundaries = Intersects(boundaries, $feature);
if(isempty(intersectBoundaries)){
return;
//{"errorMessage": "Error 2"};
};

var structureBoundary = First(intersectBoundaries);
if(isempty(structureBoundary)){
return;
//{"errorMessage": "Error 3"};
}

var AllAssemblys = FeatureSetByName($datastore, "FLUVIUS_1091_DESIGN.UTROOT.ElectricAssembly", ["assetgroup", "globalid"], true);
if(isempty(AllAssemblys)){
return;
//{"errorMessage": "Error 4"};
}

var XYassembly = Filter(AllAssemblys, filterAssembly)
if(isempty(XYassembly)){
return;
//{"errorMessage": "Error 5"};
};

var intersectAssembly = Intersects(XYassembly, structureBoundary);
if(isempty(intersectBoundaries)){
return;
//{"errorMessage": "Error 6"};
};

var assemblyGeo = First(intersectAssembly)
if(isempty(assemblyGeo)){
return;
//{"errorMessage": "Error 7"};
}


return {
"edit":
[
{"className": update_class_asso,
"updates":[{
"globalid": assemblyGeo.globalid,
"associationType":"container"
}],
'updates': [{
'globalID': assemblyGeo.globalid,
'attributes': {
'ASSET_NUMBER': "Test"
}
}]
}]
}
}

 

Third script:

// MV Connector Line (Verbindingskabel) whithout Containment -> MV Substation
if (($feature.assetgroup == 929 && $feature.ASSET_NUMBER == "associate")) {
var update_class = 'ElectricLine'
var update_class_asso = 'ElectricAssembly'
var filterAssembly = "ASSETGROUP = 904"

var boundaries = FeatureSetByName($datastore, "FLUVIUS_1091_DESIGN.UTROOT.StructureBoundary", ["globalid"], true);
if(isempty(boundaries)){
return;
//{"errorMessage": "Error 1"};
};

var intersectBoundaries = Intersects(boundaries, $feature);
if(isempty(intersectBoundaries)){
return;
//{"errorMessage": "Error 2"};
};

var structureBoundary = First(intersectBoundaries);
if(isempty(structureBoundary)){
return;
//{"errorMessage": "Error 3"};
}

var AllAssemblys = FeatureSetByName($datastore, "FLUVIUS_1091_DESIGN.UTROOT.ElectricAssembly", ["assetgroup", "globalid"], true);
if(isempty(AllAssemblys)){
return;
//{"errorMessage": "Error 4"};
}

var XYassembly = Filter(AllAssemblys, filterAssembly)
if(isempty(XYassembly)){
return;
//{"errorMessage": "Error 5"};
};

var intersectAssembly = Intersects(XYassembly, structureBoundary);
if(isempty(intersectBoundaries)){
return;
//{"errorMessage": "Error 6"};
};

var assemblyGeo = First(intersectAssembly)
if(isempty(assemblyGeo)){
return;
//{"errorMessage": "Error 7"};
}


return {
"edit":[{
"className": update_class,
'updates': [{
'globalID': $feature.globalid,
'attributes': {
'ASSET_NUMBER': "Test"
}
}]
}]
}
}

0 Kudos
4 Replies
MikeMillerGIS
Esri Frequent Contributor

If you want to edit the attribute of the edited feature, you need to return "resullt".

https://pro.arcgis.com/en/pro-app/2.9/help/data/geodatabases/overview/attribute-rule-dictionary-keyw...

 

 

return {
    //result is a dictionary
    "result": {
        "attributes": {
            "ASSET_NUMBER": 'Test'
        }
    },
   "edit":[
      {
         "className":"update_class_asso",
         "updates":[
            {
               "globalid":"assemblyGeo.globalid",
               "associationType":"container"
            }
         ]
      }
   ]
}

 

 

0 Kudos
PeterStampfl
New Contributor II

Thank you for your answer.

I tried that possibility too and now I retried it. But it did neither work.


I tried also to set only a return value and set a target field. But nothing happend if I set the Attribut Rule trigger settings only to "Insert". If I set the trigger settings to "Insert" and "Update" it works. Or if I set the trigger settings to "Insert" and unckeck "Editable". But it does not help, because in both cases it is not possible to modify the value afterwards manually.
This behavior it seems like a bug to me.

0 Kudos
HusseinNasser2
Esri Contributor

It is not recommended to change the $feature attributes through edit dictionary, the AR loses context and you can get into cyclic triggers and infinite loops. No different than recursion in programming.

Instead, set the field type to null and use the result dictionary object, this way we are able to update the attributes of the new feature in row buffer and flush it once to the database.

After rewriting your attribute rule with this mind it works. I just changed asset_number to labeltext which is the field i had on my UN (see gif) 

conn.gif

 

 

 

HusseinNasser2_0-1670874295216.png

 

// MV Connector Line (Verbindingskabel) whithout Containment -> MV Substation
if (($feature.labeltext == "associate")) {
    var update_class = 'ElectricDistributionLine'
    var update_class_asso = 'ElectricDistributionAssembly'
    var filterAssembly = ""

    var boundaries = FeatureSetByName($datastore, "StructureBoundary", ["globalid"], true);
    if (isempty(boundaries)) {
        return;
        //{"errorMessage": "Error 1"};
    };

    var intersectBoundaries = Intersects(boundaries, $feature);
    if (isempty(intersectBoundaries)) {
        return;
        //{"errorMessage": "Error 2"};
    };

    var structureBoundary = First(intersectBoundaries);
    if (isempty(structureBoundary)) {
        return;
        //{"errorMessage": "Error 3"};
    }

    var AllAssemblys = FeatureSetByName($datastore, "ElectricDistributionAssembly", ["assetgroup", "globalid"], true);
    if (isempty(AllAssemblys)) {
        return;
        //{"errorMessage": "Error 4"};
    }

    var XYassembly = Filter(AllAssemblys, filterAssembly)
    if (isempty(XYassembly)) {
        return;
        //{"errorMessage": "Error 5"};
    };

    var intersectAssembly = Intersects(XYassembly, structureBoundary);
    if (isempty(intersectBoundaries)) {
        return;
        //{"errorMessage": "Error 6"};
    };

    var assemblyGeo = First(intersectAssembly)
    if (isempty(assemblyGeo)) {
        return;
        //{"errorMessage": "Error 7"};
    }


    return {

        "result": {
            "attributes": {
                "labeltext": "test"
            }
        },
        "edit": [{
            "className": update_class_asso,
            "updates": [{
                "globalid": assemblyGeo.globalid,
                "associationType": "container"
            }]
        }]
    }
}

 

0 Kudos
PeterStampfl
New Contributor II

Hi and thank you for your answer.
I did also try the result dictonary but I did not change anything neither.
Could it be a bug?

0 Kudos