Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

to remove space from Sam account name

Aparna
New Contributor III
New Contributor III

Hi Team,

we have the  sam account name logic as below , but due the same if there is a space in the name for eg first name John Last Name S M then the sam Account name is getting created with space to over come the same we have implemented the below logic , but the add account task is getting failed with error as below .

Sam Account name logic --

"sAMAccountName":"${
String samAccountName = '';
String fn = '';
String ln = '';
 
if(user.preferedFirstName != null && !user.preferedFirstName.trim().isEmpty() && !user.preferedFirstName.trim().equalsIgnoreCase('-')){
fn = user.preferedFirstName.trim().toLowerCase();
}
else{
fn = user.firstname.trim().toLowerCase();
}
if(user.displayname != null && !user.displayname.trim().isEmpty() && !user.displayname.trim().equalsIgnoreCase('-')){

ln = user.displayname.trim().toLowerCase();

}
else{

ln = user.lastname.trim().toLowerCase();

}
samAccountName = fn.substring(0,1) + '.' + ((ln.length()<11)?ln:ln.substring(0, 11)) + '_adm';
return samAccountName;
 
Logic to remove space ---

ln = user.displayname.replaceAll("\\s","").trim().toLowerCase();

ln = user.lastname.replaceAll("\\s","").trim().toLowerCase();

 

Error in Provisioning new account --

Error while creating account in AD - Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed: SimpleTemplateScript455.groovy: 7: unexpected char: '\' @ line 7, column 35. ln = user.displayname.replaceAll(\\\s\,\"\").trim().toLowerCase(); ^ 1 error

3 REPLIES 3

Dhruv_S
Saviynt Employee
Saviynt Employee

Hi @Aparna 

Please try replacing replaceAll("\\s","") with replaceAll('\\s','') everywhere and check if it works.

Regards,
Dhruv Sharma
If the response is helpful, please click Accept As Solution and kudos it.

Aparna
New Contributor III
New Contributor III

Hi Dhruv,

Thanks will check the solution and post if any issue .

Manu269
All-Star
All-Star

@Aparna can you try :

ln = user.displayname.replaceAll('\\s',"").trim().toLowerCase();

ln = user.lastname.replaceAll('\\s',"").trim().toLowerCase();

Regards
Manish Kumar
If the response answered your query, please Accept As Solution and Kudos
.