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
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
You try to modify variables during runtime. Appian follows a functional paradigm and does not support the way of programming you might be used to.
And there is also not concept or need for any kind of explicit definition of a "return" value. An expression just creates some output.
Working code could look like this:
a!localVariables( local!userList: { "derek.romeo@gg.com", "gloria.juarez@gg.com", "pearson.vue@gg.com", "stefan.price@gg.com" }, a!forEach( items: local!userList, expression: concat( left(fv!item, 1), extract(fv!item, ".", "@") ) ), )
Hi @Stefan,
Thank you so much for the clarification. The code did work with your input. I'll have to learn more about functional paradigm.
Kind Regards,
Ritika
Hi,
Will it work?
a!localVariables( local!appianUsernames: { "test@mail.com", "test.user1", "Test_ServiceAccount" }, a!flatten( a!forEach( items: local!appianUsernames, expression: joinarray( { user(fv!item, "firstName"), user(fv!item, "lastName") }, " " ) ) ) )
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.
Hi Mike,
Thank you so much for the clarification!!