Select to view content in your preferred language

FeatureSetByAssociation function takes only $feature as input

1161
5
Jump to solution
07-26-2022 06:59 AM
OlgaKoblet
Emerging Contributor

Hi all,

as described in this blog, we can use the FeatureSetByAssociation function, for example, to get all the containments of the station boundary. However, there is a message that the syntax is invalid if  there is a variable as input (not $feature). Does anyone has an idea how to fix it?

Thank you.

 

var boundaries = FeatureSetByName($datastore, 'StructureBoundary', ['globalid'], true) //get all structure boundaries with geometry
var intersect = Intersects(boundaries, $feature) //get all boundaries that intersect with created feature
var stationBoundary = First(intersect) //select first station boundary (the only one) in order to convert from featureSet to feature
var content = FeatureSetByAssociation(stationBoundary, 'content') //get all containments of stationBoundary -> ERROR Invalid expression. Feature expected.
var assembly = Filter(content, "className = 'ElectricAssembly'") //filter containments for electricAssemblies

return{ //returns nothing - edits to containment of class "ElectricAssembly" with globalid of assembly
"edit":[{
"className": "^UN_Association",
"adds": [{
"fromClass": "ElectricAssembly",
"fromGlobalId": "assembly.globalid",
"toClass": "ElectricJunction",
"toGlobalId": "$feature.globalId",
"associationType": "container"
}]
}]
}

0 Kudos
1 Solution

Accepted Solutions
MikeMillerGIS
Esri Frequent Contributor

I believe the code is correct, but the validation logic is not returning a feature.  So you just need to add a check for if stationBoundary is null and that way the validator exits early.

Add this under var stationBoundary  = First(.....

if (IsEmpty(stationBoundary)){

  return;

}

View solution in original post

5 Replies
MikeMillerGIS
Esri Frequent Contributor

I believe the code is correct, but the validation logic is not returning a feature.  So you just need to add a check for if stationBoundary is null and that way the validator exits early.

Add this under var stationBoundary  = First(.....

if (IsEmpty(stationBoundary)){

  return;

}

StefanAngerer
Regular Contributor

I work on the same problem as @OlgaKoblet and yes: the code finally validates. However, if we try to execute the code and create a new feature, it says that the Association already exists which - as far as I am concerned - shouldn't be possible, as we make a new association with a feature that isn't even there at the moment. Any tips on how we could solve this?

Code:

var boundaries = FeatureSetByName($datastore, "StructureBoundary", ["globalid"], true); 
if(isempty(boundaries)){
return {"errorMessage": "no boundaries found."};
};

var intersectBoundaries = Intersects(boundaries, $feature); 
if(isempty(intersectBoundaries)){
return {"errorMessage": "no intersected boundaries found."};
};

var structureBoundary = First(intersectBoundaries); 
if(isempty(structureBoundary)){
return {"errorMessage": "no structure boundary found."};

var contentOfBoundary = FeatureSetByAssociation(structureBoundary, "content"); 
if(isempty(contentOfBoundary)){
return {"errorMessage": "no content found."};

var assembly = First(contentOfBoundary)  
if(isempty(assembly)){
return {"errorMessage": "no assembly found."};

return{ 
    "edit":[{
        "className": "^UN_Association",
        "adds": [{
            "fromClass": "ElectricAssembly",
            "fromGlobalId": "assembly.globalid",
            "toClass": "ElectricJunction",
            "toGlobalId": "$feature.globalid",
            "associationType": "containment"
        }]
    }]
}

 

Throws this Error:

StefanAngerer_2-1658927286799.png

 


Thanks and kind regards!

 

 

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

The error is likely because of a duplicate association in your UN.  This sound very similar to Bug BUG-000147861. Can you find that feature with the global id?  You may have to look at the association table.  The UDMS toolset has a GP tool that will generate a view of your association table.  Apply a def filter on this using the reported global IDs and see if there is indeed a duplicate association.

 

 

 

PeterStampfl
Emerging Contributor

How do I generate the view of the association tables? Which tool in GP tool I have to use? And how?
Thanks and kind regards!

0 Kudos
MikeMillerGIS
Esri Frequent Contributor