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

CASE statement in CREATEACCOUNTJSON for AD accounts

glegault
New Contributor II
New Contributor II

When creating AD Accounts in our environment we need to be able to configure different UserPrincipalName (UPN) based on the company name.

Is it possible to use CASE statements in CREATEACCOUNTJSON on the AD connexion?

We are doing something similar on our email generation rule, but I wasn’t sure if this is also an option in CREATEACCOUNTJSON. If not, we would like to know how to achieve this using another technique.

Example:

CASE
WHEN (users.companyname like '%company1.com%') THEN lower(concat(substring(users.systemUserName,1,8),'@company1.com'))

WHEN (users.companyname like '%company2.com%') THEN lower(concat(substring(users.systemUserName,1,8),'@company2.com'))

ELSE lower(concat(substring(users.systemUserName,1,8),'@defaultcompany.com'))

END

Thank you for the help!

2 REPLIES 2

rushikeshvartak
All-Star
All-Star

In Json you need to use if-else or java ternary condition ( java function and not mysql)

"companyname": "${ if(user?.companyname.contains('company1.com'))
{user?.systemUserName.substring(0, Math.min(8, systemUserName.length())).concat("@company1.com").toLowerCase()}
else {if (user?.companyname.contains('company2.com')
{user?.systemUserName.substring(0, Math.min(8, systemUserName.length())).concat("@company2.com").toLowerCase()}
else 
{user?.systemUserName.substring(0, Math.min(8, systemUserName.length())).concat("@defaultcompany.com").toLowerCase()}}}"

 

 


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

Hi rushikeshvartak,

Thank you very much for this useful information. I was able to make this work, but I had to work around a few issues along the road and make some adjustments from your suggestion.

I am sharing this here in case someone else needs to do something similar and run into similar issues.

  • I was getting syntax errors near the double quotes after the concat that I replaced with simple quotes and it worked. Was this the thing to do? Was there another option?
  • I was getting another error near the last else to set the default value. I changed this to add another if instead which does not change the logic and worked around this error.
  • There was a closing ) missing in the second if.
  • At the beginning I changed “companyname” by “userPrincipalName” since this is the property we are configuring.

Your suggestion:

"companyname": "${ if(user?.companyname.contains('company1.com')) {user?.systemUserName.substring(0, Math.min(8, sy...} else {if (user?.companyname.contains('company2.com') {user?.systemUserName.substring(0, Math.min(8, systemUserName.length())).concat("@company2.com").toLowerCase()} else {user?.systemUserName.substring(0, Math.min(8, systemUserName.length())).concat("@defaultcompany.com").toLowerCase()}}}"

What worked for me looks like this:

"userPrincipalName": "${ if(user?.companyname.contains(defaultcompany)) {user?.systemUserName.concat('@defaultcompany.com').toLowerCase()} else {if(user?.companyname.contains('company1')) {user?.systemUserName.concat('@company1.com').toLowerCase()} else {if (user?.companyname.contains('company2')) {user?.systemUserName.concat('@company2.com').toLowerCase()}}}}",

Thank you again for the help!