Auto generate number field with masked number

Rajkumar Bommal
Tera Contributor

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.

1 ACCEPTED SOLUTION

@Rajkumar Bommal 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Mark Manders
Mega Patron

You can use a before insert BR to do that, or utilize the script field on the record producer to update the number that is set to the field.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

@Mark Manders 
-->here in record producer, we are not using number field
-->when a record got created from record producer the number field in table will be auto generated with few       letters masked as mentioned previously .
---> and i have used a before insert rule also and its not working.

@Rajkumar Bommal 

so you are using the number field which is auto generated

it has prefix and before that prefix you want to add 2000

what script did you try and what debugging did you do?

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@Rajkumar Bommal 

you can use before insert business rule and handle the logic and manipulate the auto number generated

what script did you start with?

is user entering some number on record producer variable? how does that record producer look like?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader