*****This Runs First***** // This conditional statement checks if any of the specified conditions are true. // If true, the code execution stops and returns nothing. if ($feature.datelocated == null || count(attachments($feature)) != 0 || $feature.revisitReason == 'PhotoFound') { return; } // Initializing an empty object to store attributes. var att = { }; // Checks if the 'revisit' attribute is null or equal to 1. // If true, assigns the 'revisit' attribute in 'att' object a value of 0. if ($feature.revisit == null || $feature.revisit == 1) { att['revisit'] = 0; } // Checks if the string 'No Photo' is not found in the 'revisitReason' attribute. // If true, assigns 'att['revisitReason']' the value 'No Photo'. // Otherwise, appends 'No Photo' to the existing 'revisitReason' attribute value, separated by a space. if (find('No Photo', $feature.revisitReason) == -1) { if ($feature.revisitReason == null) { att['revisitReason'] = 'No Photo'; } else { att['revisitReason'] = Trim(Concatenate([$feature.revisitReason, 'No Photo'], ' ')); } } // Returns an object containing the 'att' object as the 'attributes' property. return { "result": { "attributes": att } }; ******This Runs Second****** // Checks if the 'datelocated' attribute is null and the 'revisitReason' attribute is not equal to 2. // If true, the code execution stops and returns nothing. if ($feature.datelocated == null && $feature.revisitReason != 2) // Return if the feature has not been located { return; } // Initializing an empty object to store attributes. var att = { }; // Checks if the 'revisitReason' attribute is not null. if ($feature.revisitReason != null) { // Checks if the 'revisitReason' attribute is equal to 'PhotoFound'. // If true, sets the 'revisitReason' attribute in 'att' object to null. // Additionally, if the 'revisit' attribute is not null, sets it to null as well. if ($feature.revisitReason == 'PhotoFound') { att['revisitReason'] = null; if ($feature.revisit != null) { att['revisit'] = null; } } // Checks if the string 'PhotoFound' is found in the 'revisitReason' attribute. // If true, removes 'PhotoFound' from the 'revisitReason' attribute value using the 'Replace' function. else if (find('PhotoFound', $feature.revisitReason) != -1) { att['revisitReason'] = Trim((Replace($feature.revisitReason, 'PhotoFound', ''))) } } // Checks if the 'revisit' attribute is equal to 2. // If true, sets the 'revisitReason' and 'revisit' attributes in 'att' object to null. if ($feature.revisit == 2) { if ($feature.revisitReason != null) { att['revisitReason'] = null; } if ($feature.revisit != null) { att['revisit'] = null; } } // Returns an object containing the 'att' object as the 'attributes' property. return { "result": { "attributes": att } }; *****This Runs Third, Triggering The First Two To Run Again***** // Assigning the value of the 'REL_GLOBALID' attribute to the 'attachmentKey' variable. var attachmentKey = $feature.REL_GLOBALID; // Retrieving a feature set based on the relationship name 'DATA.wServiceValves__ATTACHREL' and selecting the attributes 'revisitReason' and 'GlobalID'. var serviceValveDefinition = FeatureSetByRelationshipName($feature, "DATA.wServiceValves__ATTACHREL", ['revisitReason', 'GlobalID']); // Filtering the 'serviceValveDefinition' feature set to find the feature with a 'GlobalID' matching the 'attachmentKey'. var serviceValveSelection = First(Filter(serviceValveDefinition, "GlobalID = @attachmentKey")); // If no feature is found based on the 'attachmentKey', the code execution stops and returns nothing. if (serviceValveSelection == null) { return; } // Initializing an empty 'update' object to store attribute updates. var update = { }; // Checking if the 'revisitReason' attribute of 'serviceValveSelection' is 'No Photo'. // If true, assigns 'update.revisitReason' the value 'PhotoFound'. // Otherwise, replaces the string 'No Photo' with 'PhotoFound' in the 'revisitReason' attribute value of 'serviceValveSelection' and assigns it to 'update.revisitReason'. if (serviceValveSelection.revisitReason == 'No Photo') { update.revisitReason = 'PhotoFound'; } else { update.revisitReason = Trim(Replace(serviceValveSelection.revisitReason, 'No Photo', 'PhotoFound')); } // Returns an object containing the 'CONTENT_TYPE' attribute value of $feature, and an 'edit' array with the necessary information for updating the corresponding feature. // This is done to trigger a rule on Photo Update and Photo Check. return { "result": $feature.CONTENT_TYPE, "edit": [ { "className": "DATA.wServiceValves", "updates": [ { "globalID": serviceValveSelection.GlobalID, "attributes": update } ] } ] };