Sample Scripts BPM
Start Step
1. Calculate the email when firstName or lastName change and depending on the userType:
firstName = (inputFields.get("firstName")!=null) ? inputFields.get("firstName").value : null;
lastName = (inputFields.get("lastName")!=null) ? inputFields.get("lastName").value : null;
userType = (inputFields.get("userType")!=null) ? inputFields.get("userType").value : null;
if (firstName!=null && !firstName.trim().isEmpty() &&
lastName!=null && !lastName.trim().isEmpty() &&
userType!=null && !userType.trim().isEmpty()) {
emailAddress = firstName + "." + lastName;
if ("E".equals(userType)) {
emailAddress = emailAddress + ".ext@soffid.com";
} else {
emailAddress = emailAddress + "@soffid.com";
}
inputFields.get("emailAddress").value = emailAddress;
}
2. Calculate the user name depending on the first and last name
firstName = (inputFields.get("firstName")!=null) ? inputFields.get("firstName").value : null;
lastName = (inputFields.get("lastName")!=null) ? inputFields.get("lastName").value : null;
middleName = (inputFields.get("middleName")!=null) ? inputFields.get("middleName").value : null;
userType = (inputFields.get("userType")!=null) ? inputFields.get("userType").value : null;
primaryGroup = (inputFields.get("primaryGroup")!=null) ? inputFields.get("primaryGroup").value : null;
if (firstName!=null && !firstName.trim().isEmpty() &&
lastName!=null && !lastName.trim().isEmpty()) {
// Erase blanck spaces
while (firstName.contains(" "))
firstName = firstName.replace(" "," ");
fn = firstName.trim().split(" ")[0];
fn = fn.substring(0,1).toUpperCase() + fn.substring(1).toLowerCase();
// Erase blanck spaces
while (lastName.contains(" "))
lastName = lastName.replace(" "," ");
lna = lastName.trim().split(" ");
ln = "";
for (w : lna) {
ln = ln + w.substring(0,1).toUpperCase() + w.substring(1).toLowerCase();
}
un = fn+"."+ln;
// Check, if user exist we will add the first letter of the second name
u = serviceLocator.getUserService().findUserByUserName(un);
if (u!=null && middleName!=null && !middleName.trim().isEmpty()) {
un = un+middleName.substring(0,1).toUpperCase();
}
// Max length 20 characters
if (un.length()>20)
un = un.substring(0,20);
inputFields.get("userName").value = un;
}