Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate random code using SuiteScript

I create a new lead in NS. And go to the UE script > execution log subtab, there should be a log that contains an 8-character pseudorandom code. How can I generate random code using SuiteScript?

like image 429
Core Avatar asked Jan 22 '26 14:01

Core


1 Answers

To generate random code in suitescript, you can use Math functions.

function generateRandomCode(length){
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    let result = '';

    for (let i = 0; i < length; i++) {
        const randomIndex = Math.floor(Math.random() * characters.length);
        result += characters.charAt(randomIndex);
    }

    return result;
}
like image 136
Serhii Stepanenko Avatar answered Jan 24 '26 12:01

Serhii Stepanenko