How to user Substring function in create account JSON

Gopi
New Contributor II
New Contributor II

Hi team,

Here I need to truncate the samAccountName into 20 chars not more than 20 chars while creating the account. i.e first the system username should be 12 chars+cadmin 5 chars+ rest for increment. 

I tried in different ways like:

cadmin$substring(user.systemUserName,1,12), cadmin + substring(user.systemUserName,1,12).

Can you provide the proper syntax for a substring or is there any other way to achieve this? 

 

Thanks,

Gopi.

8 REPLIES 8

rushikeshvartak
All-Star
All-Star

user.systemUserName.toString().substring(1,12)

Gopi
New Contributor II
New Contributor II

Hi Rushikesh,

I tried the syntax which you provided. But it not resolving please check the logs.

1. "sAMAccountName":"user.systemUserName.toString().substring(1,15)" //user.systemUserName.toString().substring(1,12)
Logs:
[sAMAccountName:user.systemUserName.toString().substring(1,15),accountExpires:0,instanceType:4,givenName:tdemo,objectClass:[top, person, organizationalPerson, user],UnicodePwd:****,description:Domain Admin AFRE2,cn:dadmintsavxrazafindralambo,employeeid:980296,employeeNumber:tsavxrazafindralambo,msDS-SupportedEncryptionTypes:24,displayname:Faliarisonina Razafindralambo,sn:SAVXRazafindralambo,department:AFR,userAccountControl:512,userPrincipalName:dadmintsavxrazafindralambo@int.imf.org,objectCategory:CN=Person,CN=Schema,CN=Configuration,DC=lab,DC=imf,DC=org,pwdLastSet:0,]
2022-12-13/06:25:11.254 [{}] [quartzScheduler_Worker-12] ERROR ldap.SaviyntGroovyLdapService - Error while creating account in AD - [LDAP: error code 80 - 00000523: SysErr: DSID-031A1242, problem 22 (Invalid argument), data 0


2. "sAMAccountName":"(${user.systemUserName}.toString().substring(1,12))",
Logs:
EPLICA,DC=intstg,DC=lab,DC=imf,DC=org Datamap--[sAMAccountName:(tsavxrazafindralambo.toString().substring(1,12)),accountExpires:0,instanceType:4,givenName:tdemo,objectClass:[top, person, organizationalPerson, user],UnicodePwd:****,description:Domain Admin AFRE2,cn:dadmintsavxrazafindralambo,employeeid:980296,employeeNumber:tsavxrazafindralambo,msDS-SupportedEncryptionTypes:24,displayname:Faliarisonina Razafindralambo,sn:SAVXRazafindralambo,department:AFR,userAccountControl:512,userPrincipalName:dadmintsavxrazafindralambo@int.imf.org,objectCategory:CN=Person,CN=Schema,CN=Configuration,DC=lab,DC=imf,DC=org,pwdLastSet:0,]
2022-12-13/06:15:08.755 [{}] [quartzScheduler_Worker-11] ERROR ldap.SaviyntGroovyLdapService - Error while creating account in AD - [LDAP: error code 80 - 00000523: SysErr: DSID-031A1242, problem 22 (Invalid argument), data 0


3. "sAMAccountName":"concat('dadmin',${user.systemUserName}.substring(0,20))",
Logs:
[sAMAccountName:concat('dadmin',tsavxrazafindralambo.substring(0,20)),accountExpires:0,instanceType:4,givenName:tdemo,objectClass:[top, person, organizationalPerson, user],UnicodePwd:****,description:Domain Admin AFRE2,cn:dadmintsavxrazafindralambo,employeeid:980296,employeeNumber:tsavxrazafindralambo,msDS-SupportedEncryptionTypes:24,displayname:Faliarisonina Razafindralambo,sn:SAVXRazafindralambo,department:AFR,userAccountControl:512,userPrincipalName:dadmintsavxrazafindralambo@int.imf.org,objectCategory:CN=Person,CN=Schema,CN=Configuration,DC=lab,DC=imf,DC=org,pwdLastSet:0,]

 

Regards,
Gopi.

Please share full json

Siva
New Contributor II
New Contributor II

Hi @rushikeshvartak,
Good Afternoon!
we are also facing the same issue when we are adding substring function in the update account json in ADSI we are getting below error.

 
Error processing task of ADSI - Ambiguous method overloading for method java.lang.Exception#<init>. Cannot resolve which method to invoke for [null] due to overlapping prototypes between: [class java.lang.Throwable] [class java.lang.String].
 
we used  this in json:
 
"givenName": "${if(user.firstname.toString().substring(8,1)=='-'){concat (upper (SUBSTRING(firstname, 1, 1))}else{user.firstname}}",

Could you pls suggest any other function that would work in this situation?

Thanks 
Siva

I see a format issue in the statement used in concat block,

1. I don't see concat block is closed 

2. I don't see a string with which you are concatenating 

"givenName": "${if(user.firstname.toString().substring(8,1)=='-'){concat (upper (SUBSTRING(firstname, 1, 1))}else{user.firstname}}",


Regards,
Saathvik

Siva
New Contributor II
New Contributor II

Hi Sk,

We changed the json and using the below mentioned json

"givenName":"${if(user?.firstname.toString().substring(8,1)=='-'){user?.firstname.toString().substring(0,1).toUpperCase()}else{user.firstname}}"

But still its throwing the same error

Could you please help me in this ?

Thanks 
Siva

Do you see any error?

What is the sample data for firstname and expected value for givenname?

Also please share full JSON


Regards,
Saathvik

Siva
New Contributor II
New Contributor II

Hi Sk

This is the error its throwing:-

Error processing task of ADSI - Ambiguous method overloading for method java.lang.Exception#<init>. Cannot resolve which method to invoke for [null] due to overlapping prototypes between: [class java.lang.Throwable] [class java.lang.String].

if Firstname = JEAN PIERRE    then Givenname = Jean Pierre

Full json:-

{
"objects": [{
"objectClasses": [
"user"
],
"distinguishedName": "${account.accountID}",
"moveObjectToOU": "${if(account.accounttype==null || account.accounttype=='' || account.accounttype=='Primary Account'){user.customproperty5}else{''}}",
"deleteAllGroups": "Yes",
"attributes": {
"userPrincipalName":"${user.customproperty2}",
"title": "${if(user.jobDescription == null){''}else{user.jobDescription}}",
"sn": "${if(user.lastname == null){''}else{user.lastname.toUpperCase()}}",
"samaccountname": "${if(account.accounttype=='Primary Account'){user.customproperty1}else{account.name}}",
"cn": "${if(user.customproperty13 == null){''}else{user.customproperty13}}",
"userAccountControl": "${if(account.accounttype == 'Technical Account'){account.customproperty7}else{'512'}}",
"company":"${if(user.customproperty3 == '89'){'ADECCO IT SERVICES'} else if(user.customproperty3 == '65'){'ADECCO MEDICAL'} else if(user.customproperty3 == '18'){'ADECCO TRAINING'} else if(user.customproperty3 == '39'){'PONTOON'} else if(user.customproperty3 == '52'){'HUMANDO'} else if(user.customproperty3 == '57'){'HUMANDO PLURIELS'} else if(user.customproperty3 == '58'){'HUMANDO COMPETENCES'} else if(user.customproperty3 == '60'){'ADECCO DIGITAL France'}else{''}}",
"co":"${if(user.customproperty3=='89' || user.customproperty3=='65' || user.customproperty3=='18' || user.customproperty3=='39' || user.customproperty3=='52' || user.customproperty3=='57' || user.customproperty3=='58' || user.customproperty3=='60'){'France'}else{''}}",
"info":"${if(user.customproperty15 == 'AITS External Offshore' && user.employeeType!='Permanent Employee' && account.accounttype=='Primary Account'){'MBXP1'}else if((user.customproperty15 == 'AITS External Adely' || user.customproperty15 == 'AITS External Front de Parc' || user.customproperty3=='65') && (user.employeeType!='Permanent Employee') && (account.accounttype=='Primary Account')){'MBXE1'}else if(account.accounttype=='Technical Account'){''}else{'MBX'}}",
"c":"FR",
"department": "${if(account.accounttype == 'Primary Account' && null != user.departmentname){user.departmentname}else{account.customproperty8}}",
"displayName": "${if(null!=user.displayname && account.accounttype=='Primary Account'){user.displayname}else{account.displayName}}",
"employeeID": "${if(null!=user.employeeid && account.accounttype=='Primary Account'){user.employeeid}else{account.customproperty1}}",
"employeeNumber": "${if(null!=user.employeeid && account.accounttype=='Primary Account'){user.employeeid}else{account.customproperty19}}",
"employeeType": "${if(account.accounttype == 'Technical Account' || account.accounttype==null){account.customproperty14} else if(user.employeeType=='Permanent Employee' && account.accounttype=='Primary Account'){'Colleague'}else{'Contractor'}}",
"givenName":"${if(user?.firstname.toString().substring(8,1)=='-'){user?.firstname.toString().substring(0,1).toUpperCase()}else{user.firstname}}"
"pwdlastset": "0",
"division":"${if(user.customproperty23 == null){''}else{user.customproperty23}}",
"scriptPath":"${if(user.customproperty3 == '65'){'logon_AMS_migration.vbs'} else{''}}",
"manager": "${if(user.customproperty6 == null && user.customproperty36 == null){''} else if(user.customproperty36==null){user.customproperty6}else{user.customproperty36}}",
"msDS-cloudExtensionAttribute5":"${if(user.customproperty24 == null){''}else{user.customproperty24}}"
}
}]
}


Thanks
Siva