// Updating Asset IDs // SCENARIO #1: I'm creating a New Feature. // DTP_Asset_ID is empty. // Select a category from DTP_Cat2. // Get the latest ID from DTP_Counter and add 1. // Then calc into DTP_Asset_ID. if(IsEmpty($feature.DTP_Counter)) { var DTP = $featureset // Use the GroupBy function to summarize on DTP_Cat2 and grab the highest value. // For example, DTP_Cat2 = "STP-PSO-CO" and there are 100 features in that category. This returns the following: // DTP_Counter = 100 // DTP_Cat2 = "STP-PSO-CO" // Max_ID = 100 var DTP_Grouped = GroupBy(OrderBy(DTP, 'DTP_Counter ASC'), 'DTP_Cat2', { name:'Max_ID', expression:'DTP_Counter', statistic: 'MAX' } ); var DTP_Value = $feature.DTP_Cat2 // "STP-PSO-CO" var DTP_Grouped_Filter = Filter(DTP_Grouped, 'DTP_Cat2 = @DTP_Value') for (var i in DTP_Grouped_Filter) { var new_id = i.Max_ID + 1 } // new_id = 101 return new_id; } // SCENARIO #2: I'm editing an Existing feature but I won't change the DTP_Cat2 category. Thus don't change the DTP_Asset_ID. // If DTP_Cat2 value is in DTP_Asset_ID, don't change DTP_Asset_ID. // i.e. DTP_Cat2 = "STP-PSO-CO" and DTP_Asset_ID = "STP-PSO-CO-5", leave the Asset ID as is. else if (!IsEmpty($feature.DTP_Asset_ID) && Find($feature.DTP_Cat2,$feature.DTP_Asset_ID) > -1) { return $feature.DTP_Asset_ID; } // SCENARIO #3: I'm editing an Existing feature AND I change the DTP_Cat2 category. Thus I need to change the DTP_Asset_ID. // DTP_Asset_ID is not empty. // Get the latest ID from DTP_Counter and add 1. Then calc into DTP_Asset_ID. else if(!IsEmpty($feature.DTP_Counter && Find($feature.DTP_Cat2,$feature.DTP_Asset_ID) = -1) { var DTP = $featureset // Use the GroupBy function to summarize on DTP_Cat2 and grab the highest value. // For example, DTP_Cat2 = "STP-PSO-CO" and there are 100 features in that category. This returns the following: // DTP_Cat2 = "STP-PSO-CO" // Max_ID = 100 var DTP_Grouped = GroupBy(OrderBy(DTP, 'DTP_Counter ASC'), 'DTP_Cat2', { name:'Max_ID', expression:'DTP_Counter', statistic: 'MAX' } ); var DTP_Value = $feature.DTP_Cat2 // "STP-PSO-CO" var DTP_Grouped_Filter = Filter(DTP_Grouped, 'DTP_Cat2 = @DTP_Value') for (var i in DTP_Grouped_Filter) { if(Find(DTP_Value, $feature.DTP_Asset_ID) > -1) { // "STP-PSO-CO" in "STP-PSO-CO-5" var new_id = i.Max_ID } else { var new_id = i.Max_ID + 1 } } }