Hi Rutuja,
Please see this forum post that suggests to use "Random Hash" from the marketplace module "Community Commons".
There's also this marketplace component, which might help.
If you want to follow the Javascript approach, this solution could be adapted to your needs, although I suggest to avoid it, as a low-code approach is preferable in this case (easier to read and to maintain...).
let currentId = 'A0000';
function generateUniqueId() {
let prefix = currentId.substring(0, 1);
let number = parseInt(currentId.substring(1));
if (number < 9999) {
number++;
} else {
let prefixCharCode = prefix.charCodeAt(0);
if (prefixCharCode < 90) {
prefix = String.fromCharCode(prefixCharCode + 1);
} else {
prefix = 'A';
}
number = 0;
}
currentId = prefix + number.toString().padStart(4, '0');
return currentId;
}
// Example usage
for (let i = 0; i < 30; i++) {
console.log(generateUniqueId());
}
Hope this helps.
One of the possible solutions is to use substring and ParseInteger to separate your string part ("A", "BB" or whatever else) from the integer part that is incremented and then merge them back during the creation of a new object.