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.
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()) {
while (firstName.contains(" "))
firstName = firstName.replace(" "," ");
fn = firstName.trim().split(" ")[0];
fn = fn.substring(0,1).toUpperCase() + fn.substring(1).toLowerCase();
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;
// Confirmamos si existe y le aƱadimos la primera letra del segundo apellido
u = serviceLocator.getUserService().findUserByUserName(un);
if (u!=null && middleName!=null && !middleName.trim().isEmpty()) {
un = un+middleName.substring(0,1).toUpperCase();
}
// Cortamos si es muy largo
if (un.length()>20)
un = un.substring(0,20);
inputFields.get("userName").value = un;
}
if (firstName!=null && !firstName.trim().isEmpty() &&
lastName!=null && !lastName.trim().isEmpty() &&
userType!=null && !userType.trim().isEmpty() &&
primaryGroup!=null && !primaryGroup.trim().isEmpty()) {
// Username
while (firstName.contains(" "))
firstName = firstName.replace(" "," ");
fn = firstName.trim().split(" ")[0];
fn = fn.substring(0,1).toUpperCase() + fn.substring(1).toLowerCase();
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;
// Confirmamos si existe y le aƱadimos la primera letra del segundo apellido
u = serviceLocator.getUserService().findUserByUserName(un);
if (u!=null && middleName!=null && !middleName.trim().isEmpty()) {
un = un+middleName.substring(0,1).toUpperCase();
}
// Cortamos si es muy largo
if (un.length()>20)
un = un.substring(0,20);
// Mail
ea = un;
if ("E".equals(userType))
ea = ea+".external";
if ("TFM".equals(primaryGroup)) {
ea = ea+"@soffid.com";
} else {
ea = ea+"@soffid-soffid.com";
}
// Formulario
inputFields.get("emailAddress").value = ea.toLowerCase();
}