How do I generate a coupon code for users in Xano?

Options
raelyn
raelyn Member
edited August 2023 in ? Help! I'm a Noob

How do I generate a coupon code for users?

Ideally, I want it to be the user's first name in caps followed by a 6-digit string of random letters AND numbers.

This is something similar to the 4-digit auth code, but… now we are including letters.

Example code would be: JOHNDOE7BK3HE (all is in caps)I know there is a"Generate Random Number" function but what about random letters and numbers generator?

Tagged:

Answers

  • jakespirek
    jakespirek Member, Administrator

    ADMIN

    Options

    Hi @raelyn this may take some experimentation on your side, but for the name part you can concatenate their first and last name and then use to_upper to convert the case.

    For the random alphanumeric portion, one thing you could try is creating a secret key which will obviously be too long at first.

    Then you can split the text (leave the separator field empty). The secret key will also include some hyphens/underscores so you could replace/remove those if they show up.

    Now that you have an array, slice it with the length you want.

    Join the results with an empty separator and convert to uppercase.

    Then concatenate that to the name portion you did earlier.

    Again, will take some experimentation, but hopefully that gives you ideas!

  • Brandon Hassler
    Options

    Im on my phone right now so I can't check (easily) but there should also be a function that is a simple random number generator and you can select the exact number of digits (and then concat to the same as Jake said).

  • raelyn
    raelyn Member
    edited August 2023
    Options

    Hey @jakespirek! How do I remove the dashes and underscores? Thank you :)

    EDIT: Managed to solve this using Lambda:)