Calculate/concatenate depending on field values

793
10
Jump to solution
01-17-2023 04:40 PM
VanessaSimps
Occasional Contributor III

Hello-

I am trying to write an attribute rule that will calculate a field value by concatenating other fields. I have the basic arcade written, however, we have some variation in our table that could cause the straightforward statements to not work as I want. Here is what I need:

Prefix + Route + Week -- the field can only be 5 characters long total -- ex CC01S or D005N or CB005 or D0005

  • Prefix could be one or two characters, ex: CC, D, CB
  • Route has a value like 001, 005, 011
  • Week = North or South-- I amusing the following to pull off only the first letter of the word: LEFT($feature.COMMERCIAL_WEEK,1)

My thought is that if I can identify whether or not the following is true I can create the new concatenated field:

  • Identify if Week is null. THIS WORKS
// First determine if there is week information
// If there is, add 'week' sufix to it
var wmWeek = null;
if (!IsEmpty($feature.CASTERBOXCARDBOARD_WEEK)){
  wmWeek = LEFT($feature.CASTERBOXCARDBOARD_WEEK,1);
}
  • Identify if prefix value is one or two characters long. This would allow me to know how many leading zeros are needed from the route field. This is also the step where I get stuck. What I need to be able to write is something like:
    • IF Prefix is >1 return Route = RIGHT($feature.Route,2)
    • else IF Prefix is <1 return Route = RIGHT($feature.route,1)

Here is what I have working so far thanks to a couple of blog posts I found:

//works, getting closer- need to figure out the prefix when 2 characters and the route 0001 vs 001 vs 01

// First determine if there is week information
// If there is, add 'week' sufix to it
var wmWeek = null;
if (!IsEmpty($feature.CASTERBOXCARDBOARD_WEEK)){
  wmWeek = LEFT($feature.CASTERBOXCARDBOARD_WEEK,1);
}

//Second determin if the prefix is one or two characters
var prefix = $feature.CASTERBOXCARDBOARD_PREFIX
var route = $feature.CASTERBOXCARDBOARD_ROUTE

if (prefix is >1){

}
//List of fields to combine
var parts =[$feature.CASTERBOXCARDBOARD_PREFIX,$feature.CASTERBOXCARDBOARD_ROUTE,wmWeek];

//loop through parts, if null/empty add to new array
var filteredparts =[];
for (var i in parts) {
var value = parts[i];
if (isEmpty(value)) continue;
filteredparts[Count(filteredparts)] =value
}
//Concatenate
return concatenate(filteredparts,"");

  

any help or ideas here would be great!

0 Kudos
10 Replies
VanessaSimps
Occasional Contributor III

@DonSjoboen  see if this give you any hints!

 

0 Kudos