- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2025 06:07 PM
Hello,
I'm working on importing a list of records into ServiceNow, and I want to ensure that for every record being inserted into the database, the first letter of each word in the relevant fields is capitalized.
For example, if the imported data contains a field like "james miller", it should be inserted as "James Miller".
Can anyone provide guidance on how to achieve this in ServiceNow during the import process?
Any suggestions on scripting or configurations would be greatly appreciated!
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2025 07:18 PM
you can use field map script or transform map onBefore script
something like this
(function transformEntry(source, target, map, log, isUpdate) {
// Function to capitalize the first letter of each word
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
// Apply the function to the relevant fields
target.field_name = toTitleCase(source.field_name);
// Repeat for other fields as needed
})(source, target, map, log, isUpdate);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2025 10:30 PM
Hello @kusumgautam
You can follow approach provided by Ankur which is specific for one field to target record field. But sometimes we have requirement where we have multiple field which need same, so instead of writing script over each field we can go with below approach.
First a script include named as "CapitalizeWords" which should be client callable and its script as below:
var CapitalizeWords = Class.create();
CapitalizeWords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
capitalize: function(input) {
if (!input) return '';
return input.replace(/\b\w/g, function(char) {
return char.toUpperCase();
});
},
type: 'CapitalizeWords'
});
In your transform map, you will need to create a onBefore transform script, code as below:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
var capitalizeWords = new CapitalizeWords();
// List of fields to capitalize
var fieldsToCapitalize = ['first_name', 'last_name', 'full_name']; // Replace with your field names
fieldsToCapitalize.forEach(function(field) {
if (source[field]) {
target[field] = capitalizeWords.capitalize(source[field]);
}
});
})(source, map, log, target);
The transform script will ensure that the first letter of each word in the specified fields is capitalized before the records are inserted into the database.
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2025 07:18 PM
you can use field map script or transform map onBefore script
something like this
(function transformEntry(source, target, map, log, isUpdate) {
// Function to capitalize the first letter of each word
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
// Apply the function to the relevant fields
target.field_name = toTitleCase(source.field_name);
// Repeat for other fields as needed
})(source, target, map, log, isUpdate);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2025 10:30 PM
Hello @kusumgautam
You can follow approach provided by Ankur which is specific for one field to target record field. But sometimes we have requirement where we have multiple field which need same, so instead of writing script over each field we can go with below approach.
First a script include named as "CapitalizeWords" which should be client callable and its script as below:
var CapitalizeWords = Class.create();
CapitalizeWords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
capitalize: function(input) {
if (!input) return '';
return input.replace(/\b\w/g, function(char) {
return char.toUpperCase();
});
},
type: 'CapitalizeWords'
});
In your transform map, you will need to create a onBefore transform script, code as below:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
// Add your code here
var capitalizeWords = new CapitalizeWords();
// List of fields to capitalize
var fieldsToCapitalize = ['first_name', 'last_name', 'full_name']; // Replace with your field names
fieldsToCapitalize.forEach(function(field) {
if (source[field]) {
target[field] = capitalizeWords.capitalize(source[field]);
}
});
})(source, map, log, target);
The transform script will ensure that the first letter of each word in the specified fields is capitalized before the records are inserted into the database.
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2025 10:17 PM
Hi @kusumgautam
You can write the below scrip in Transform script section (onBefore script)
function xx(str) {
return str.replace(/\w\S*/g, function(word) {
return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase();
});
}
// Example usage: Applying the function to a field
target.field_name = xx(source.field_name);
note :- It uses regular expressions (/\w\S*/g) to match words in the string and applies the transformation using JavaScript's replace() function.
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/