Here is what I got so far
I have a user input selection that has 2 choices and I need the referral code generated when they select yes how do i do so?
Code:
$w("#createProfileButton").onClick(() => { let fname = $w("#firstName").value; let lname = $w("#lastName").value; let phone = $w("#phoneNumber").value; let refCode = fname.slice(0, 2).toLocaleLowerCase() + phone.slice(phone.length - 4, phone.length) + lname.slice(0, 2).toLocaleLowerCase(); let toInsert = { "firstName": fname, "lastName": lname, "emailAddress": $w("#emailAddress").value, "phone": phone, "username": $w("#userName").value, "referredBy": $w("#referredBy").value, "referralCode": refCode }; wixData.insert("profile", toInsert) .then(() => { wixLocation.to("/account/profile-page"); }) .catch((err) => { //check error codes and see if taken or not. let errorMsg = err; // $w("#error").show(); });
I recommend installing the Faker node package and using something like its UUID function.
Save their details to your "profile" collection then run a query on the "profile" collection and search for the entry you have just made in your collection. There will be a number of different field keys for the entry such as username, phone, emailAddress. Get the value for the field key called _id. Then display this as the refCode on the page.