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

Convert String to Title Case

Diego
New Contributor II
New Contributor II

Is there an easier way to convert strings into Title Case format? Currently I have the following logic in CreateAccountJSON API call to ServiceNow which works as expected:

 

\"u_employee_name_middle\":\"${user.middlename==null?'':user.middlename.contains(' ')?user.middlename.split(' ')[0].substring(0,1) + user.middlename.split(' ')[0].substring(1).toLowerCase() + ' '
+ user.middlename.split(' ')[1].substring(0,1) + user.middlename.split(' ')[1].substring(1).toLowerCase():user.middlename.substring(0,1) + user.middlename.substring(1).toLowerCase()}\",

User's middle names are all in uppercase in our user schema.

There is a case where users have multiple middle names. That is why you me using split logic to handle the scenario where a user has 2 middle names. In my if-logic I use .contains(' ') because these other methods did not work as if-conditions: 

 

user.middlename.split(' ')[1] == null
user.middlename.split(' ')[1] != null
user.middlename.split(' ').length > 0
user.middlename.split(' ').length == 2
 
Is there a reason why these do not work?

 

 

4 REPLIES 4

rushikeshvartak
All-Star
All-Star

You can create dyanmic attributes and manage this using sql query and use dynamic attribute variables in json


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

Do you happen to have an example or documentation I could use to change our middle name values to title case using sql query? I already know how to use dynamic attributes within the JSON.

Select CONCAT(UPPER(SUBSTRING(firstname,1,1)),LOWER(SUBSTRING(firstname,2))) AS Name FROM USERS 


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

Would this handle the scenario in which users have multiple middle names?

Select CONCAT(UPPER(SUBSTRING(middlename,1,1)),LOWER(SUBSTRING(middlename,2))) AS Name FROM USERS 

For example, a user with middle names BYAN SMITH. Would this logic convert these names into Byan Smith? How about user's with a hyphenated middle name? For example, BYAN-SMITH?