Hi All,
I am trying to achieve the below in an Appian expression rule;
Expression Rule will have two inputs, firstName (Text), lastName (Text). It prepares a username with the logic as below.
concat( lower( split( ri!firstName, " " ) ), ".", lower( split( ri!lastName, " " ) ) )
But what I need is if the isusernametaken of that result is true, I have to append 1 and return the username.
Even if that is unavailable, I have to append 2 and return the username.
This should continue until a username is returned which is available.
Example:-
Inputs:-
firstName -> John Rod
lastName -> Williams
username -> johnrod.williams
If the above username is not available, it should return johnrod.williams1. Even if it is not available, return johnrod.williams2
How can we achieve this in an Expression Rule?
Thank you,
Arun
Discussion posts and replies are publicly visible
You can accomplish this using two rules - here is a snippet and you will likely want to add error handling (check for nulls as well as limit the ri!num to be < 100 or something)
Parent Rule:
if( isusernametaken(ri!firstName & " " & ri!lastName), rule!recursiveUsername(firstName: ri!firstName, lastName: ri!lastName, num: 1), ri!firstName & " " & ri!lastName )
Recursive rule:
if( isusernametaken(ri!firstName & " " & ri!lastName & ri!num), rule!recursiveUsername(firstName: ri!firstName, lastName: ri!lastName, num: ri!num + 1), ri!firstName & " " & ri!lastName & ri!num )