3

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?

Core
  • 37
  • 5

1 Answers1

3

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;
}