Hi Philippe,
I have written code for uniqueness check of email as like user id, but it's not working.
Requirement is Firstname+Lastname+n@domain, 'n' should vary from 1-99.
Please find below code and suggest if I missed anything
function handleValidation(blthContext, errorMsg) {
var user = blthContext.getUser();
var FirstName = user.getAttribute("%FIRST_NAME%");
var LastName = user.getAttribute("%LAST_NAME%");
if (FirstName.isEmpty() || LastName.isEmpty()) {
// this message will be presented on the Screen
errorMsg.reference = "Failed to build an mail, First name and last name are required";
return false;
}
var mail = FirstName + "." + LastName+ "0" + "@adek.gov.ae";
var userbis = blthContext.getUserProvider();
for (var n=0; n<=99; n++){
try {
mail = FirstName + "." + LastName+ n + "@adek.gov.ae";
userbis.findUserDuplicate(mail, null);
//mail already exists, search for next computed one
if (n==99) {
// this message will be presented on the Screen
errorMsg.reference = "Failed to find an mailID,all mailIDs already exist";
return false;
}
} catch (nso){
break; //Not such object
}
}
try {
blthContext.getUser().setAttribute("%EMAIL%", mail);
} catch (ex) {
//this message will be presented on the screen
errorMsg.reference = "Failed to set an mail" + ex.getMessage();
return false;
}
return true;
}
Original Message:
Sent: 05-14-2018 06:33 AM
From: Philippe Guihard
Subject: Re: BLTH for UserID creation CA IDM 14.2
Hi Randeep,
I see 3 typos:
Line 10 should be (no parenthesis):
errorMsg.reference = "Failed to build an UID, First name, last name and department number are required";
Line 18 should be (starting index in first sub string is zero not o):
UID = FirstName.substring(0, 1) + LastName.substring(0, 1) + String.fromCharCode(c) + departmentNumber;
Line 31 should be (setAtttribute function does not exist):
blthContext.getUser().setAttribute("%USER_ID%", UID);
Regards,
Philippe.