- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 11:39 PM
Hi,
am working on a record producer , i want to Auto-generated running number field in table (2000 appended with masked NRIC, leaving last 4 characters visible) 2000-*****123F, when record is inserted in the table.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2025 02:19 AM
is this field "nric" mapped with some variable?
How it's getting populated?
Did you print what came in that field in your BR?
try this and share what came in logs
(function executeRule(current, previous /*null when async*/) {
gs.info('Business Rule started for record: ' + current.sys_id);
// Convert NRIC to string to ensure proper slicing
var nric = current.nric + '';
gs.info('NRIC value: ' + nric);
// Check if NRIC length is at least 4 characters
if (nric.length >= 4) {
// Get the last four characters of the NRIC
var lastFour = nric.slice(-4);
gs.info('Last four characters of NRIC: ' + lastFour);
// Set the identification number with the masked NRIC
current.u_identification_number = '2000-*****' + lastFour;
gs.info('Generated identification number: ' + current.u_identification_number);
} else {
// Handle cases where NRIC is less than 4 characters
current.u_identification_number = '2000-*****ERR';
gs.info('NRIC is less than 4 characters, setting identification number to: ' + current.u_identification_number);
}
gs.info('Business Rule completed for record: ' + current.sys_id);
})(current, previous);
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
05-08-2025 02:11 AM
@Ankur Bawiskar
No user won't enter any number in record Producer all he enter is details of the employee and his managing person details
i have used a script in business rule but it is not working
Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2025 02:19 AM
is this field "nric" mapped with some variable?
How it's getting populated?
Did you print what came in that field in your BR?
try this and share what came in logs
(function executeRule(current, previous /*null when async*/) {
gs.info('Business Rule started for record: ' + current.sys_id);
// Convert NRIC to string to ensure proper slicing
var nric = current.nric + '';
gs.info('NRIC value: ' + nric);
// Check if NRIC length is at least 4 characters
if (nric.length >= 4) {
// Get the last four characters of the NRIC
var lastFour = nric.slice(-4);
gs.info('Last four characters of NRIC: ' + lastFour);
// Set the identification number with the masked NRIC
current.u_identification_number = '2000-*****' + lastFour;
gs.info('Generated identification number: ' + current.u_identification_number);
} else {
// Handle cases where NRIC is less than 4 characters
current.u_identification_number = '2000-*****ERR';
gs.info('NRIC is less than 4 characters, setting identification number to: ' + current.u_identification_number);
}
gs.info('Business Rule completed for record: ' + current.sys_id);
})(current, previous);
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
07-04-2025 04:43 AM
Hope you are doing good.
Did my reply answer your question?
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