<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Update field in Parent layer IF related layer record is given specific field value in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596082#M1710</link>
    <description>&lt;P&gt;Line 13 is not doing what you think it is.&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#featuresetbyrelationshipname" target="_self"&gt;FeatureSetByRelationshipName&lt;/A&gt; returns the related records for a given $feature, your parents that are return for that specific $feature.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;If I'm assuming correctly you are trying to collect all the&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;WNV_SiteVisits for each, filtered, for your&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;WNV_StagnantWaterSites and then update.&lt;BR /&gt;&lt;BR /&gt;If correct, you would either need this on your&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;WNV_StagnantWaterSites with some sort of trigger or as a batch calculation.&lt;BR /&gt;&lt;BR /&gt;Because this is a M:N relationship if applied to the&amp;nbsp;&lt;SPAN&gt;WNV_SiteVisits&lt;/SPAN&gt; you would have to go get all your&amp;nbsp;&lt;SPAN&gt;WNV_StagnantWaterSites&lt;/SPAN&gt;parents that are related to that one $feature (&lt;SPAN&gt;FeatureSetByRelationshipName)&lt;/SPAN&gt;.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var parentGlobalList = []

var parentFeatures = FeatureSetByRelationshipName($feature, relationshipName, ["GLOBALID"], true);

for (var parent in parentFeatures){
    Push(parentGlobalList, parent.GLOBALID)
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;Once you have those &lt;SPAN&gt;WNV_StagnantWaterSites.&lt;/SPAN&gt;GlobalIDs you would have to find a way to get back to the&amp;nbsp;&lt;SPAN&gt;WNV_SiteVisits and get the related visits for each&amp;nbsp;WNV_StagnantWaterSites GlobalID. Currently I do not believe there is a way to go backwards in a relationship. I'd love to be wrong and I hope the greater community can correct me.&lt;BR /&gt;&lt;BR /&gt;If you can..... use that list to iterate over each globalid in the list to get all the related&amp;nbsp;WNV_SiteVisits.&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;Then filter. Get your count and push your &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;edit up to a dictionary of globals&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Push(parentUpdates, {
    'attributes': Dictionary(
        SiteRisk, newSiteRisk)
})&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;to then push your edits in your return dictionary.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Mar 2025 14:42:28 GMT</pubDate>
    <dc:creator>Jake_S</dc:creator>
    <dc:date>2025-03-17T14:42:28Z</dc:date>
    <item>
      <title>Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1595940#M1708</link>
      <description>&lt;P&gt;I'm struggling to get this attribute rule working.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Setup:&lt;/STRONG&gt;&lt;BR /&gt;Parent Layer: WNV_StagnantWaterSites (point feature class)&lt;BR /&gt;Related Layer: WNV_SiteVisits (point feature class)&lt;BR /&gt;Relationship: 1:M (SiteCode as Primary &amp;amp; Foreign Key, short numeric)&lt;BR /&gt;Notification: Both directions&lt;BR /&gt;Record Count: 628 parent records, 50,000+ related records&lt;BR /&gt;Relationship Class: WNV_StagnantWaterSites_TO_WNV_SiteVisits&lt;BR /&gt;&lt;STRONG&gt;Goal:&lt;/STRONG&gt;&lt;BR /&gt;I need to update the SiteRisk field (text: "Other", "Low", "Moderate", "High") in WNV_StagnantWaterSites based on related WNV_SiteVisits records where LarvacideRequest = 1 (Yes) in the last 12 months (SiteVisitDate field).&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Logic:&lt;/STRONG&gt;&lt;BR /&gt;0 records → SiteRisk = Low&lt;BR /&gt;1 record → SiteRisk = Moderate&lt;BR /&gt;2+ records → SiteRisk = High&lt;BR /&gt;Downgrades:&lt;BR /&gt;High → Moderate if no Yes records in 12 months&lt;BR /&gt;Moderate → Low if no Yes records in 12 months&lt;BR /&gt;Issue:&lt;BR /&gt;My attribute rule validates and saves, but SiteRisk does not update, no matter how I modify WNV_SiteVisits. Any help from an Attribute Rule Guru would be greatly appreciated!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":folded_hands:"&gt;🙏&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;// Relationship class name
var relationshipName = "WNV_StagnantWaterSites_TO_WNV_SiteVisits";

// Define the cutoff date for the last 12 months
var today = Now();
var twelveMonthsAgo = DateAdd(today, -12, "months");

// Fetch related site visit records (Child Features)
var relatedVisits = FeatureSetByRelationshipName($feature, relationshipName, ["LarvacideRequest", "SiteVisitDate"], false);

// Debugging: Log how many related visits were found
Console("&lt;span class="lia-unicode-emoji" title=":magnifying_glass_tilted_left:"&gt;🔍&lt;/span&gt; Found " + Count(relatedVisits) + " related site visit records.");

// Filter visits where LarvacideRequest = 1 (Yes) AND occurred in the past 12 months
var recentLarvacideVisits = Filter(relatedVisits, "LarvacideRequest = 1 AND SiteVisitDate &amp;gt;= @twelveMonthsAgo");

// Count qualifying visits
var visitCount = Count(recentLarvacideVisits);

// Debugging: Log how many visits met the criteria
Console(":calendar:&lt;/img&gt; " + visitCount + " site visits in the past 12 months had LarvacideRequest = 1.");

// Determine new SiteRisk value based on visit count
var newSiteRisk = "";
if (visitCount == 0) {
    newSiteRisk = "Low";
} else if (visitCount == 1) {
    newSiteRisk = "Moderate";
} else if (visitCount &amp;gt;= 2) {
    newSiteRisk = "High";
}

// Fetch the parent feature (WNV_StagnantWaterSites)
var parentFeatures = FeatureSetByRelationshipName($feature, relationshipName, ["SiteRisk"], true);

// Ensure we have at least one parent
if (Count(parentFeatures) &amp;gt; 0) {
    var parent = First(parentFeatures);

    // Get the existing SiteRisk value
    var currentRisk = parent.SiteRisk;

    // Debugging: Log the existing SiteRisk before updating
    Console("&lt;span class="lia-unicode-emoji" title=":counterclockwise_arrows_button:"&gt;🔄&lt;/span&gt; Current SiteRisk: " + currentRisk);

    // Only update if the risk level actually changes
    if (currentRisk != newSiteRisk) {
        Console("&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; Updating SiteRisk from " + currentRisk + " to " + newSiteRisk);
        
        return {
            "edit": [
                {
                    "className": "WNV_StagnantWaterSites",
                    "updates": [
                        {
                            "objectID": parent.OBJECTID,
                            "attributes": {
                                "SiteRisk": newSiteRisk
                            }
                        }
                    ]
                }
            ]
        };
    } else {
        Console(":warning:&lt;/img&gt; No update needed. SiteRisk remains: " + currentRisk);
    }
} else {
    Console("&lt;span class="lia-unicode-emoji" title=":cross_mark:"&gt;❌&lt;/span&gt; No parent found for this site visit.");
}

// No update needed
return null;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Mar 2025 04:56:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1595940#M1708</guid>
      <dc:creator>JamesBooth</dc:creator>
      <dc:date>2025-03-17T04:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596034#M1709</link>
      <description>&lt;P&gt;Hey James,&lt;/P&gt;&lt;P&gt;Couple things. In your return you are using the&amp;nbsp;&lt;SPAN&gt;parent&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;OBJECTID (line 56), I would use a globalId. you can get this from your relationship class.&lt;BR /&gt;&lt;BR /&gt;Also, I would just return, not return null (line 73). A simple return ends the expression evaluation, a return null, is trying to populate an objects field value with null.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Start there, and let us know what happens.&lt;BR /&gt;&lt;BR /&gt;~Jake&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Mar 2025 13:32:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596034#M1709</guid>
      <dc:creator>Jake_S</dc:creator>
      <dc:date>2025-03-17T13:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596082#M1710</link>
      <description>&lt;P&gt;Line 13 is not doing what you think it is.&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#featuresetbyrelationshipname" target="_self"&gt;FeatureSetByRelationshipName&lt;/A&gt; returns the related records for a given $feature, your parents that are return for that specific $feature.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;If I'm assuming correctly you are trying to collect all the&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;WNV_SiteVisits for each, filtered, for your&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;WNV_StagnantWaterSites and then update.&lt;BR /&gt;&lt;BR /&gt;If correct, you would either need this on your&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;WNV_StagnantWaterSites with some sort of trigger or as a batch calculation.&lt;BR /&gt;&lt;BR /&gt;Because this is a M:N relationship if applied to the&amp;nbsp;&lt;SPAN&gt;WNV_SiteVisits&lt;/SPAN&gt; you would have to go get all your&amp;nbsp;&lt;SPAN&gt;WNV_StagnantWaterSites&lt;/SPAN&gt;parents that are related to that one $feature (&lt;SPAN&gt;FeatureSetByRelationshipName)&lt;/SPAN&gt;.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var parentGlobalList = []

var parentFeatures = FeatureSetByRelationshipName($feature, relationshipName, ["GLOBALID"], true);

for (var parent in parentFeatures){
    Push(parentGlobalList, parent.GLOBALID)
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;Once you have those &lt;SPAN&gt;WNV_StagnantWaterSites.&lt;/SPAN&gt;GlobalIDs you would have to find a way to get back to the&amp;nbsp;&lt;SPAN&gt;WNV_SiteVisits and get the related visits for each&amp;nbsp;WNV_StagnantWaterSites GlobalID. Currently I do not believe there is a way to go backwards in a relationship. I'd love to be wrong and I hope the greater community can correct me.&lt;BR /&gt;&lt;BR /&gt;If you can..... use that list to iterate over each globalid in the list to get all the related&amp;nbsp;WNV_SiteVisits.&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;Then filter. Get your count and push your &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;edit up to a dictionary of globals&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Push(parentUpdates, {
    'attributes': Dictionary(
        SiteRisk, newSiteRisk)
})&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;to then push your edits in your return dictionary.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Mar 2025 14:42:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596082#M1710</guid>
      <dc:creator>Jake_S</dc:creator>
      <dc:date>2025-03-17T14:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596309#M1711</link>
      <description>&lt;P class="lia-align-left"&gt;Thanks for your response Jake! I appreciate your assistance very much! I'm completely new to Arcade and I'll admit I'm using AI tools to assist, which is why I'm likely having issues. My relationship&amp;nbsp; between WNV_StagnantWaterSites and WNV_SiteVisits is actually 1:M. I have one WNV_StagnantWaterSites record with multiple WNV_SiteVisits records. Both are point feature classes. Parent represents the Stagnant Water Site. Child records are point locations surrounding the stagnant water site. Staff want to know specifically where students are collecting on a pond as an example.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I tried your suggestions of using GlobalID instead of ObjectID and I also removed the return null, and just have return. Unfortunately, I still don't have my SiteRisk level changing. Even if I trigger the rule by applying a LarvacideRequest = "1" (Yes), nothing happens to the SiteRisk in the parent point feature layer. My updated syntax is at bottom.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I also wonder what my execution parameters should be set at. This is what I have:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JamesBooth_0-1742242682482.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/128091i843886EC8030EFF2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JamesBooth_0-1742242682482.png" alt="JamesBooth_0-1742242682482.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;// Define the related records from the WNV_SiteVisits layer
var relatedRecords = FeatureSetByRelationshipName($feature, "SDEDB1.GISADMIN.WNV_StagnantWaterSites_TO_WNV_SiteVisits");
var currentDate = Now();
var oneYearAgo = DateAdd(currentDate, -1, 'years');
var larvacideRequestCount = 0;

// Iterate through related records to count LarvacideRequest values of "1" (Yes) in the past 12 months
for (var record in relatedRecords) {
    if (record["LarvacideRequest"] == 1 &amp;amp;&amp;amp; record["SiteVisitDate"] &amp;gt;= oneYearAgo) {
        larvacideRequestCount++;
    }
}

// Determine the new SiteRisk value based on the count of LarvacideRequest values
var newSiteRisk = "";
if (larvacideRequestCount == 0) {
    newSiteRisk = "Low";
} else if (larvacideRequestCount == 1) {
    newSiteRisk = "Moderate";
} else if (larvacideRequestCount &amp;gt;= 2) {
    newSiteRisk = "High";
}

// Update the parent record's SiteRisk field if it needs to be changed
if ($feature["SiteRisk"] != newSiteRisk) {
    return {
        "edit": [{
            "className": "SDEDB1.GISADMIN.WNV_StagnantWaterSites",
            "updates": [{
                "GlobalID": $feature["GlobalID"],
                "attributes": {
                    "SiteRisk": newSiteRisk
                }
            }]
        }]
    };
}

// End the expression evaluation if no update is needed
return;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Mar 2025 20:19:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596309#M1711</guid>
      <dc:creator>JamesBooth</dc:creator>
      <dc:date>2025-03-17T20:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596502#M1713</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/39320"&gt;@JamesBooth&lt;/a&gt;&amp;nbsp;my apologies, I glossed over the initial part not realizing the relationship was 1:M.&lt;BR /&gt;&lt;BR /&gt;Few questions,&lt;BR /&gt;&lt;BR /&gt;Can you provide a screenshot of that relationship properties?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;catalog &amp;gt; right click relationship &amp;gt; properties&lt;/P&gt;&lt;P&gt;Also are you able provide empty data sets for the schema (create a copy and delete the contents)? If not that's fine.&lt;/P&gt;&lt;P&gt;I's want to test a solution.&lt;BR /&gt;&lt;BR /&gt;~Jake&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 12:13:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596502#M1713</guid>
      <dc:creator>Jake_S</dc:creator>
      <dc:date>2025-03-18T12:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596527#M1714</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/39320"&gt;@JamesBooth&lt;/a&gt;&amp;nbsp;did a recording that may help.&amp;nbsp;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6370187426112w996h540r21" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6370187426112" data-account="6161463677001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6161463677001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6370187426112w996h540r21');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://community.esri.com/t5/video/gallerypage/video-id/6370187426112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 13:22:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596527#M1714</guid>
      <dc:creator>Jake_S</dc:creator>
      <dc:date>2025-03-18T13:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596590#M1716</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JamesBooth_0-1742311375858.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/128157iDDAC6F1495603359/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JamesBooth_0-1742311375858.png" alt="JamesBooth_0-1742311375858.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 15:23:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596590#M1716</guid>
      <dc:creator>JamesBooth</dc:creator>
      <dc:date>2025-03-18T15:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596591#M1717</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/39320"&gt;@JamesBooth&lt;/a&gt;&amp;nbsp;well I love to be proven wrong, even by me.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://media1.giphy.com/media/v1.Y2lkPTc5MGI3NjExN3V4cWl5cjZtZWJkOWxpYzBsNTJlOWoyd2U0Zmp3YmczbnJkbXAwMiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/EbNRa9eE9YHni/giphy.gif" border="0" /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Relationship class name
var relationshipName = "WNV_StagnantWaterSites_TO_WNV_SiteVisits";
var parentGlobalID;
var newSiteRisk = "";

// Define the cutoff date for the last 12 months
var today = Now();
var twelveMonthsAgo = DateAdd(today, -12, "months");

// Fetch related parent record (WNV_StagnantWaterSites)
var relatedParent = FeatureSetByRelationshipName($feature, "WNV_StagnantWaterSites_TO_WNV_SiteVisits", ["GlobalID"], false);

for (var parent in relatedParent) {
    parentGlobalID = parent.GlobalID;
    // Fetch related site visit records (Child Features)
    var relatedVisits = FeatureSetByRelationshipName(parent, "WNV_StagnantWaterSites_TO_WNV_SiteVisits", ["GlobalID","LarvacideRequest","SiteVisitDate"], false);

    // Debugging: Log how many related visits were found
    Console(" Found " + Count(relatedVisits) + " related site visit records.");

    // Filter visits where LarvacideRequest = 1 (Yes) AND occurred in the past 12 months
    var recentLarvacideVisits = Filter(relatedVisits, "LarvacideRequest = 1 AND SiteVisitDate &amp;gt;= @twelveMonthsAgo");

    // Count qualifying visits
    var visitCount = Count(recentLarvacideVisits);

    // Debugging: Log how many visits met the criteria
    Console(":calendar: " + visitCount + " site visits in the past 12 months had LarvacideRequest = 1.");

    // Determine new SiteRisk value based on visit count
    if (visitCount == 0) {
        newSiteRisk = "Low";
    } else if (visitCount == 1) {
        newSiteRisk = "Moderate";
    } else if (visitCount &amp;gt;= 2) {
        newSiteRisk = "High";
    }
}

return {
    'edit': [{
        'className': 'WNV_StagnantWaterSites',
        'updates': [{
            'globalID': parentGlobalID,
            'attributes': {
                "SiteRisk": newSiteRisk
            }
        }]
    }]
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Try this applied to your in place of your original on the&amp;nbsp;&lt;SPAN&gt;WNV_SiteVisits.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 15:25:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596591#M1717</guid>
      <dc:creator>Jake_S</dc:creator>
      <dc:date>2025-03-18T15:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596594#M1718</link>
      <description>&lt;P&gt;Thanks Jake! I will try this shortly later today and I'll let you know how it goes. I actually may not even need this rule anymore lol! Might be changing the workflow slightly so that user has more control on when SiteRisk needs changing. But I still want to see if I can get this working! So thank you! I'll keep you apprised!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 15:26:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596594#M1718</guid>
      <dc:creator>JamesBooth</dc:creator>
      <dc:date>2025-03-18T15:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596664#M1721</link>
      <description>&lt;P&gt;It works!! Fantastic. There does remain a small issue though and I'm trying to find it! The issue is deleting any WNV_SiteVisits records. If I create a new site visit and add a high larva count, which successfully triggers my "LarvacideRequest" field to become "1" (Yes), then the SiteRisk changes to moderate in the Parent, which is exactly what I want. But if I delete that WNV_SiteVisits record instantly, the SiteRisk level (value) remains the same in the Parent, and I would want it go back to 'Low' risk. I'm sure I'm missing something obvious. Add, update and delete are the triggers. And I have "exclude from application evaluation" checked because I got an error saying it needed to be checked given certain functions in the code (Edit()). Once that was checked, the attribute rule performs fine, with the exception of when I delete a WNV_SiteVisits record. SiteRisk remains the same.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 17:04:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596664#M1721</guid>
      <dc:creator>JamesBooth</dc:creator>
      <dc:date>2025-03-18T17:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596735#M1725</link>
      <description>&lt;P&gt;I saw this issue in my testing. I'm looking to get some answers internally. This was discussed way back when here&amp;nbsp;&lt;A href="https://community.esri.com/t5/geodatabase-questions/attribute-rule-delete-trigger-to-update-another/td-p/773463" target="_self"&gt;Attribute Rule Delete Trigger to Update Another Feature&lt;/A&gt;&amp;nbsp;with no luck. I tried to modify our code to use, as the article suggests, (line 10 - 14) to check if the edit is DELETE and replace $feature with $originalFeature with no luck.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Relationship class name
var relationshipName = "WNV_StagnantWaterSites_TO_WNV_SiteVisits";
var parentGlobalID;
var newSiteRisk = "";

// Define the cutoff date for the last 12 months
var today = Now();
var twelveMonthsAgo = DateAdd(today, -12, "months");

var childFeature = $feature

if ($editcontext.editType == "Delete"){
   childFeature = $originalFeature
}


// Fetch related parent record (WNV_StagnantWaterSites)
var relatedParent = FeatureSetByRelationshipName(childFeature, "WNV_StagnantWaterSites_TO_WNV_SiteVisits", ["GlobalID"], false);

for (var parent in relatedParent) {
    parentGlobalID = parent.GlobalID;
    // Fetch related site visit records (Child Features)
    var relatedVisits = FeatureSetByRelationshipName(parent, "WNV_StagnantWaterSites_TO_WNV_SiteVisits", ["GlobalID","LarvacideRequest","SiteVisitDate"], false);

    // Debugging: Log how many related visits were found
    Console(" Found " + Count(relatedVisits) + " related site visit records.");

    // Filter visits where LarvacideRequest = 1 (Yes) AND occurred in the past 12 months
    var recentLarvacideVisits = Filter(relatedVisits, "LarvacideRequest = 1 AND SiteVisitDate &amp;gt;= @twelveMonthsAgo");

    // Count qualifying visits
    var visitCount = Count(recentLarvacideVisits);

    // Debugging: Log how many visits met the criteria
    Console(":calendar: " + visitCount + " site visits in the past 12 months had LarvacideRequest = 1.");

    // Determine new SiteRisk value based on visit count
    if (visitCount == 0) {
        newSiteRisk = "Low";
    } else if (visitCount == 1) {
        newSiteRisk = "Moderate";
    } else if (visitCount &amp;gt;= 2) {
        newSiteRisk = "High";
    }
}

return {
    'edit': [{
        'className': 'WNV_StagnantWaterSites',
        'updates': [{
            'globalID': parentGlobalID,
            'attributes': {
                "SiteRisk": newSiteRisk
            }
        }]
    }]
}&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 18 Mar 2025 18:35:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596735#M1725</guid>
      <dc:creator>Jake_S</dc:creator>
      <dc:date>2025-03-18T18:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596921#M1735</link>
      <description>&lt;P&gt;I took yours above and tried this to see if it would do the trick, but no luck as well! Getting close I think though! I would think it's possible! (hopeful positivity lol!)&lt;/P&gt;&lt;LI-CODE lang="python"&gt;// Relationship class name
var relationshipName = "WNV_StagnantWaterSites_TO_WNV_SiteVisits";
var parentGlobalID;
var newSiteRisk = "";

// Define the cutoff date for the last 12 months
var today = Now();
var twelveMonthsAgo = DateAdd(today, -12, "months");

// Determine if the operation is a delete and set the correct reference
var childFeature = $feature;
if ($editcontext.editType == "Delete") {
    childFeature = $originalFeature;
}

// Fetch related parent record (WNV_StagnantWaterSites)
var relatedParent = FeatureSetByRelationshipName(childFeature, relationshipName, ["GlobalID"], false);

if (IsEmpty(relatedParent)) {
    Console("&lt;span class="lia-unicode-emoji" title=":cross_mark:"&gt;❌&lt;/span&gt; No related parent found for deleted site visit.");
    return;
} else {
    Console("&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; Found parent feature. Proceeding with update.");
}

// Process the parent feature
for (var parent in relatedParent) {
    parentGlobalID = parent.GlobalID;

    // Fetch all remaining site visits **AFTER** deletion
    var remainingVisits = FeatureSetByRelationshipName(parent, relationshipName, ["LarvacideRequest", "SiteVisitDate"], false);

    Console("&lt;span class="lia-unicode-emoji" title=":magnifying_glass_tilted_right:"&gt;🔎&lt;/span&gt; Remaining visits after delete: " + Count(remainingVisits));

    // If no visits remain, reset SiteRisk to "Low"
    if (Count(remainingVisits) == 0) {
        Console("&lt;span class="lia-unicode-emoji" title=":stop_sign:"&gt;🛑&lt;/span&gt; No remaining site visits. Resetting SiteRisk to Low.");
        newSiteRisk = "Low";
    } else {
        // Filter visits where LarvacideRequest = 1 AND occurred in the past 12 months
        var recentLarvacideVisits = Filter(remainingVisits, "LarvacideRequest = 1 AND SiteVisitDate &amp;gt;= @twelveMonthsAgo");
        var visitCount = Count(recentLarvacideVisits);

        Console(":bar_chart:&lt;/img&gt; Recalculating SiteRisk: " + visitCount + " valid site visits remain.");

        // Assign SiteRisk based on visit count
        if (visitCount == 0) {
            newSiteRisk = "Low";
        } else if (visitCount == 1) {
            newSiteRisk = "Moderate";
        } else if (visitCount &amp;gt;= 2) {
            newSiteRisk = "High";
        }
    }
}

// Apply the SiteRisk update to the parent feature
return {
    'edit': [{
        'className': 'SDEDB1.GISADMIN.WNV_StagnantWaterSites',
        'updates': [{
            'globalID': parentGlobalID,
            'attributes': {
                "SiteRisk": newSiteRisk
            }
        }]
    }]
};&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 19 Mar 2025 03:50:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1596921#M1735</guid>
      <dc:creator>JamesBooth</dc:creator>
      <dc:date>2025-03-19T03:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Update field in Parent layer IF related layer record is given specific field value</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1598522#M1741</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/39320"&gt;@JamesBooth&lt;/a&gt;&amp;nbsp;I still have not heard back from our internal resources. As soon as I do, I'll post.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2025 14:39:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/update-field-in-parent-layer-if-related-layer/m-p/1598522#M1741</guid>
      <dc:creator>Jake_S</dc:creator>
      <dc:date>2025-03-24T14:39:02Z</dc:date>
    </item>
  </channel>
</rss>

