Select to view content in your preferred language

Using attribute rules to copy attribute from one feature to another

206
2
Jump to solution
11-17-2025 07:53 AM
MelissaGearman
Occasional Contributor

I need to copy an attribute from a table to a feature class using attribute rules.

The scenario is this: I have a signs table (Signs_InOffice) that is populated with a ton of sign information (name, price, quantity, etc.).  I also have a signs report layer (Signs_InOfficeReport) that gets added to whenever a new sign gets made. What I need to happen is when a new feature gets added to the report layer, the price attribute gets populated based on the price attribute in the signs table of that same sign name.

Using the information I found on this post, I tried the following on the signs table. The expression is valid but when I go to make an update or add a new feature, the price attribute does not get populated in the report layer.

MelissaGearman_0-1763394485507.png

 

 

0 Kudos
1 Solution

Accepted Solutions
AlfredBaldenweck
MVP Regular Contributor

I'd recommend using a relationship class instead of filtering by FeatureName. This way, you can do a featuresetbyRelationship and it will automatically filter the other table. Way easier, particularly because I think the issue is in your filter.

As written, I think it's looking for the actual value "@s", which isn't going to get you anything.

If you use a template literal instead, you get better results

var s = $feature.SignName
var t = Filter(FeatureSetByName($datastore, "Signs_InOfficeReport"), 
               `SignName = '${s}'`)

if(Count(t)>0){
    var v = First(t)
    retDict = {"edit": [{"className": "Signs_InOfficeReport",
                         "updates": [{"objectID": v.ObjectID,
                                      "attributes": {"PriceEach": $feature.PriceEach}
                                     }]
                       }]
               }
    return retDict

}else{
    var retDict = {"edit": [{"className": "Signs_InOfficeReport",
                             "adds": [{"attributes": {"PriceEach": $feature.PriceEach, 
                                                     "SignName": s}
                                     }]
                           }]
                  }
    return retDict
}

 

The other thing I added here is the thing that actually inserts the record. There are more clever ways to construct your dictionary, but this is straightforward and lets you actually see what's going on.

View solution in original post

0 Kudos
2 Replies
AlfredBaldenweck
MVP Regular Contributor

I'd recommend using a relationship class instead of filtering by FeatureName. This way, you can do a featuresetbyRelationship and it will automatically filter the other table. Way easier, particularly because I think the issue is in your filter.

As written, I think it's looking for the actual value "@s", which isn't going to get you anything.

If you use a template literal instead, you get better results

var s = $feature.SignName
var t = Filter(FeatureSetByName($datastore, "Signs_InOfficeReport"), 
               `SignName = '${s}'`)

if(Count(t)>0){
    var v = First(t)
    retDict = {"edit": [{"className": "Signs_InOfficeReport",
                         "updates": [{"objectID": v.ObjectID,
                                      "attributes": {"PriceEach": $feature.PriceEach}
                                     }]
                       }]
               }
    return retDict

}else{
    var retDict = {"edit": [{"className": "Signs_InOfficeReport",
                             "adds": [{"attributes": {"PriceEach": $feature.PriceEach, 
                                                     "SignName": s}
                                     }]
                           }]
                  }
    return retDict
}

 

The other thing I added here is the thing that actually inserts the record. There are more clever ways to construct your dictionary, but this is straightforward and lets you actually see what's going on.

0 Kudos
MelissaGearman
Occasional Contributor

Thanks @AlfredBaldenweck! I figured it had something to do with the filter but I was at a loss as to what it could be. I used your script with template literals and it worked like a charm! They're something I've heard of but haven't really utilized until now.

0 Kudos