Attribue Rules - Related Table Not Found on Insert

561
4
04-27-2021 12:55 PM
IsaiahAguilera
Occasional Contributor II

Hello! I have an issue with related records on insert. TrafficSigns and TrafficSignsWorkOrder are the tables i am working with. I have a rule in TrafficSignsWorkOrder to pull the AssetID from TrafficSigns on insert. The problem is FeatureSetByRelationshipName doesn't seem to return any related records when run on Insert.

If I trigger on update the code works perfectly. But I need to trigger on insert because our crews rarely go back on edit after the initial submit. It seems there is something that prevents a related record from being returned at all on insert. Again this all works perfect on a Update. But i need it to work on Insert.

var relatedTrafficSigns = FeatureSetByRelationshipName($feature, "SDE.OWNER.TrafficSignsWorkOrder_REL", ['*'], false);
var relatedCount = Count(relatedTrafficSigns);
var relatedAssetId = "nothing";
if (relatedCount > 0) {
    var relatedAsset = First(relatedTrafficSigns);
    relatedAssetId = relatedAsset.AssetID;
    
}
return relatedAssetId;

 

Tags (2)
0 Kudos
4 Replies
JohannesLindner
MVP Frequent Contributor

Try querying the TrafficSigns yourself:

 

var trafficSignID = $feature.TrafficSignID
var trafficSigns = FeatureSetByName($datastore, "SDE.OWNER.TrafficSigns", ['TrafficSignID', 'AssetID'], false)
var relatedTrafficSigns = Filter(trafficSigns, 'TrafficSignID = @trafficSignID')
if(Count(relatedTrafficSigns) == 0) {
  return 'nothing'
}
return First(relatedTrafficSigns).AssetID

 


Have a great day!
Johannes
0 Kudos
IsaiahAguilera
Occasional Contributor II

We also tried that. Unfortunately the same result. Interestingly enough the rules work fine with Field Maps & Survey123. It's only in Pro where the rule doesn't return anything on insert. I'm not sure what is different between the different platforms.

0 Kudos
JohannesLindner
MVP Frequent Contributor

Ignoring for a moment that it works on other platforms, it sounds like it doesn't find related data because the relating field (TrafficSignID in my example code above) is empty.

Try this simple constraint rule to throw an error when you try to insert a new TrafficSignWorkOrder without a TrafficSignID:

if(IsEmpty($feature.TrafficSignID)) {
  return false
}
return true

 


Have a great day!
Johannes
0 Kudos
IsaiahAguilera
Occasional Contributor II

I should have mentioned this earlier but the relate is built on GlobalIDs so they are generated automatically. That was where my confusion was with it not returning anything in Pro. It should be automatic in my mind. 

0 Kudos