We are delighted to share our new EIC Delivery Methodology for efficiently managing Saviynt Implementations and delivering quick time to value. CLICK HERE.

to remove space from Sam account name

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 --

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

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


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


Saviynt Employee
Saviynt Employee

Hi @Aparna 

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

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

New Contributor III
New Contributor III

Hi Dhruv,

Thanks will check the solution and post if any issue .


@Aparna can you try :

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

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

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