Generating Random 6-Digit and 4-Digit Numbers in CRM

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sapyantuk
    Senior Member
    • Oct 2020
    • 265

    Generating Random 6-Digit and 4-Digit Numbers in CRM

    I have a requirement to generate a random 6-digit number within our CRM system and save it in a specific field. Could you please assist me with the steps to achieve this? Additionally, if it's possible, I would also like to know how to generate a random 4-digit number within the CRM and save it in a field.

    Thank you for your support.
  • lazovic
    Super Moderator
    • Jan 2022
    • 809

    #2
    Hi sapyantuk,

    You can use this formula script (don't forget to replace $fourDegit and $sixDegit variables names to your fields names):
    Code:
    $fourDegit = number\randomInt(0, 9999);
    
    ifThen(
    string\length($fourDegit) == 3,
    $fourDegit = string\concatenate('0', $fourDegit)
    );
    
    ifThen(
    string\length($fourDegit) == 2,
    $fourDegit = string\concatenate('00', $fourDegit)
    );
    
    ifThen(
    string\length($fourDegit) == 1,
    $fourDegit = string\concatenate('000', $fourDegit)
    );
    
    $sixDegit = number\randomInt(0, 999999);
    
    ifThen(
    string\length($sixDegit) == 5,
    $sixDegit = string\concatenate('0', $sixDegit)
    );
    
    ifThen(
    string\length($sixDegit) == 4,
    $sixDegit = string\concatenate('00', $sixDegit)
    );
    
    ifThen(
    string\length($sixDegit) == 3,
    $sixDegit = string\concatenate('000', $sixDegit)
    );
    
    ifThen(
    string\length($sixDegit) == 2,
    $sixDegit = string\concatenate('0000', $sixDegit)
    );
    
    ifThen(
    string\length($sixDegit) == 1,
    $sixDegit = string\concatenate('00000', $sixDegit)
    );

    Comment


    • esforim
      esforim commented
      Editing a comment
      Genius plan.
Working...