For  referral code generation in Power Fx

Chapter - 06

Visit to buy the book on Citizen Development https://go.citizendeveloper.codes/buynow

Code Snippet #1

For referral code generation in Power Fx

   Concat(
        FirstN(
            Shuffle(
                Split(
                    "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789",
                    ""
                )
            ),
            8
        ),
        Result
    )

Explanation

  • Split("abcdefghijklmnopqrstuvwxyz...6789", ""): - This function splits the provided string into an array of individual characters. The string is a long sequence of the alphabet followed by numbers 0 to 9, repeated several times. The split delimiter is an empty string "", so each character in the string becomes a separate item in the resulting array.

  • Shuffle(...): - This function takes the array created by Split and randomizes the order of its elements. After this, the array’s elements (individual characters) are in a random order.

  • FirstN(..., 8): - This function takes the first 8 elements from the shuffled array. Since the array was randomized by Shuffle, these 8 characters are randomly selected each time the formula is run.

  • Concat(..., Result): - The Concat function is used to concatenate (join together) the elements of the array. Concat would take an array or table and a formula to apply to each record of that array/table. In this case, it is to join the 8 random characters into a single string. If Result is intended to be used.

So, the overall purpose of this formula to generate a random string of 8 characters, each character being a letter (a-z) or a digit (0-9) i.e referral code in this case.

Happy #low-code learning

Visit: www.citizendeveloper.codes

Id: Chapter-06-CS00001

Category: Chapter 06

Amit Puri, Advisor and Consultant, Strengthening Digital Experiences, Modernize Cloud Journey with AI-Driven Transformation!