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

The script for displayname for AD type connection not working

Israr
New Contributor II
New Contributor II

Hello Team,

We are trying to use below script for display name but it is not working in lower environment.

"displayname": "${String str=task.accountName;str=str.replace('@****.com','').replace('.',' ');java.util.regex.Matcher m=java.util.regex.Pattern.compile('(\\w+)+').matcher(str);StringBuilder resultSB=new StringBuilder();while(m.find()){resultSB.append(m.group().substring(0,1).toUpperCase()).append(m.group().substring(1).toLowerCase()).append(' ');};String result=resultSB.toString().trim();str=str.trim();String finalDispName='';int i=0;int len=result.length();while(i<len){if(Character.isSpace(result.charAt(i))&&str.charAt(i)=='-'){finalDispName = finalDispName + '-';}else{finalDispName = finalDispName + result.charAt(i);}i++;}if(user.employeeType.equalsIgnoreCase('Text') && user.customproperty11.equalsIgnoreCase('NE')){finalDispName=finalDispName.concat(' (TEXTt)');return result;}else{return finalDispName;}}",

Below is the error we are getting while provisioning.

error 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: SimpleTemplateScript1079.groovy: 1: expecting '}', found 'i' @ line 1, column 623. lDispName + result.charAt(i);}i+1;};retu ^ 1 error.

Thanks!

Regards,

Israr Ahmed M

2 REPLIES 2

Dhruv_S
Saviynt Employee
Saviynt Employee

Hi @Israr 

There are syntax errors in your code causing it to fail in the compilation. Please try to compile the code in some groovy compiler before you use it in Saviynt connections.

From the code I can see first while loop ending with semicolon while second while loop not ending with semicolon. There can be multiple such issues.
Kindly review the entire logic and syntax used step by step.

"
${
String str=task.accountName;
str=str.replace('@****.com','').replace('.',' ');
java.util.regex.Matcher m=java.util.regex.Pattern.compile('(\\w+)+').matcher(str);StringBuilder resultSB=new StringBuilder();

while(m.find())
{resultSB.append(m.group().substring(0,1).toUpperCase()).append(m.group().substring(1).toLowerCase()).append(' ');};

String result=resultSB.toString().trim();
str=str.trim();
String finalDispName='';
int i=0;
int len=result.length();

while(i<len)
{if(Character.isSpace(result.charAt(i))&&str.charAt(i)=='-')
{finalDispName = finalDispName + '-';}
else{finalDispName = finalDispName + result.charAt(i);}i++;}

if(user.employeeType.equalsIgnoreCase('Text') && user.customproperty11.equalsIgnoreCase('NE'))
{finalDispName=finalDispName.concat(' (TEXTt)');return result;}else{return finalDispName;}

}
"

Israr
New Contributor II
New Contributor II

Hello Dhruv,
Thanks for your quick response.

As we tried in groovy compiler and we are getting the below as the error.

Israr_0-1706890664180.png

Below is the complete code which we are using for display name column while provisioning.

"displayname": "${String str = task.accountName;str = str.replace('****@hitech.com', '').replace('.', ' ');java.util.regex.Matcher m = java.util.regex.Pattern.compile('(\\w+)+').matcher(str);StringBuilder resultSB = new StringBuilder();while (m.find()){resultSB.append(m.group().substring(0, 1).toUpperCase()).append(m.group().substring(1).toLowerCase()).append(' ');}String result = resultSB.toString().trim();str = str.trim();String finalDispName='';int i = 0;int len=result.length();while(i<len){if (Character.isSpace(result.charAt(i)) && str.charAt(i) == '-'){finalDispName = finalDispName + '-';}else{finalDispName = finalDispName + result.charAt(i);}\\\\ni++;}if (user.employeeType.equalsIgnoreCase('XXXXX') && user.customproperty11.equalsIgnoreCase('XX')){finalDispName = finalDispName.concat(' (FF)'); return finalDispName;}else{return finalDispName;}}",

The actual requirement is here.
First the task. Account contains the email like as example.

enter-prise.test@hitech.com and in the json we have mentioned to remove the @hitech.com and Dot with space after that the remaining is left as below.

enter-prise test

Now the below code will remove the all special characters and make the firstname of first characters with uppercase and last name of first characters with upper case as like below.

Enter Prise Test

java.util.regex.Matcher m = java.util.regex.Pattern.compile('(\\w+)+').matcher(str);StringBuilder resultSB = new StringBuilder();while (m.find()){resultSB.append(m.group().substring(0, 1).toUpperCase()).append(m.group().substring(1).toLowerCase()).append(' ');}String result = resultSB.toString().trim();str = str.trim()

Now our requirement is where ever the space either in first name or last name it should be replace with Hyphen with the above format as it is.

As an above example since firstname has the space it should replace with Hiphen.

As like below display name to be printed.

Enter-Prise Test

The code we used now is below.

String finalDispName='';int i = 0;int len=result.length();while(i<len){if (Character.isSpace(result.charAt(i)) && str.charAt(i) == '-'){finalDispName = finalDispName + '-';}else{finalDispName = finalDispName + result.charAt(i);}

And with above code the task it is getting failed with below error.

 unexpected char: '\' @ line 1, column 630. lDispName + result.charAt(i);}\ni++;};r

Hence could you please help us in fixing this code and as we already tried in groovy compiler and we are getting the error i++.

Thanks!

Regards,

Israr Ahmed M