Local variable shows null despite having values.

The problem statement is:

To create a username for a person by joining their Last name and first letter of their First name.

Following is the code:

a!localVariables(
  local!userList: {
    "derek.romeo@gg.com",
    "gloria.juarez@gg.com",
    "pearson.vue@gg.com",
    "stefan.price@gg.com"
  },
  
  local!names,
  local!result,
  
  {
    a!forEach(
      items: local!userList,
      expression: {
        append(local!names,tostring(reverse(rdrop(split(split(fv!item,"@"),"."),2)))),
        local!result:{
          index(split(local!names),";")&index(index(split(local!names,";"),2),1)
        }
      }  
    ),
   
  }
)

This code is throwing the below error:

Expression evaluation error at function a!forEach [line 13]: Error in a!forEach() expression during iteration 1: Expression evaluation error at function 'split' [line 18]: A null parameter has been passed as parameter 1.

When I run the code without lines 17 and 18, I get the below result:

List of Variant - 4 items

    • List of Text String - 1 item
        • "romeo; derek"(Text)
          • List of Text String - 1 item
              • "juarez; gloria"(Text)
                • List of Text String - 1 item
                    • "vue; pearson"(Text)
                      • List of Text String - 1 item
                          • "price; stefan"(Text)

                        and this the expected answer. I am not sure when I try to use the local!names within the same forEach loop for further operations, it says it doesn't contain any values. 

                        Any help in resolving this query will be helpful. 

                        Thanks!

                          Discussion posts and replies are publicly visible

                        Parents
                        • +1
                          Certified Lead Developer

                          In addition to Stefan's correct answer, I'll point out that you seem to misunderstand what's happening when Appian displays an array.

                          If you write an expression rule that says {1, 2, 3}, the plaintext (raw) output from running the rule will show "1; 2; 3"

                          But this does NOT mean that data CONTAINS A SEMICOLON - it is only rendered AFTERWARDS as part of Appian's convention in displaying ARRAY DATA.  The ACTUAL data does not contain a semicolon.

                          So calling "split" on the result, and passing a split term of ";", will not work because there is no such thing happening in the actual data.  If it seems to work in some cases then this has happened mainly by accident.

                        Reply
                        • +1
                          Certified Lead Developer

                          In addition to Stefan's correct answer, I'll point out that you seem to misunderstand what's happening when Appian displays an array.

                          If you write an expression rule that says {1, 2, 3}, the plaintext (raw) output from running the rule will show "1; 2; 3"

                          But this does NOT mean that data CONTAINS A SEMICOLON - it is only rendered AFTERWARDS as part of Appian's convention in displaying ARRAY DATA.  The ACTUAL data does not contain a semicolon.

                          So calling "split" on the result, and passing a split term of ";", will not work because there is no such thing happening in the actual data.  If it seems to work in some cases then this has happened mainly by accident.

                        Children