I’m hoping that someone will be able to help with me with what I thought would be a simple task (I should say that I am very new to Velo and coding in general).
My requirement is to link a specific Coupon Code to a particular user account, so as to give the user a discount code to use when purchasing stuff. At this stage I’m not trying to do anything fancy like stopping transactions going through if the code doesn’t match the user (although that would be great…) - all I want to do for now is to present a Coupon Code on a member page (I’ve chosen to add a couple of fields to the My Account page).
So far, I have a content collection (“Discount Codes”) that has the company name as the primary “title” field and then two reference fields: one to the PrivateMembersData (“associatedUser”) and another to the Coupons. In this way I can link company, user, and coupon code (it would perhaps be easier if I could access the company data from Contacts, but as far as I can tell this is not possible).
On the page, I have a dataset linking to the collection (“#DiscountCodesDataset”) and a text field that is connected to the dataset is displays the Coupon Code that is pulled through via the reference in the collection. Or at least that is what I am trying to do.
I have a small bit of code that filters the dataset based on the current user:

In the Preview mode it seems to work:

But when I log in with a different username (and in a different browser, just to make sure), I get this:

Can anyone please tell me where I’m going wrong?
Thanks in advance.
If it is working on PREVIEW but not LIVE, your first question should be…
Could this behaviour be caused by → DB-Permissions?
Since you are using → PMD (PrivateMembersData) which is normaly not open for everyone, this could be already the issue in your logic.
But this is just my first quick theoretical thought, after reading your post.
Surely it will work, when → logged-in as ADMIN (Preview-Mode as i know is always → ADMIN)
And surely when you go LIVE-Mode as ADMIN, it will still work, but when switching back to another USER, it won’t.
Was my thinking right?
Hi there - thanks for your suggestion, but I don’t think it’s right, at least not for PMD, as during a first attempt to get this working I set up a grid table on the page with static data in the collection (i.e. no link to the Coupons DB) and a reference to PMD so as to filter by user and that seemed to work okay (that was when I was trying to link via Company).
It might be right for the Coupons collection, though. Unfortunately, I cannot find out how to check the permission settings for it, as the option is greyed out in the Content Manager:

…and there are no options presented in the Coupons page of the dashboard.
Any ideas?
I have also found another thread that seems to be discussing a similar issue (https://community.wix.com/partners/forum/technical-talk/database-permissions-problem-feature-request), where Brett Haralson says this:
“You cannot change permissions in the built in databases. It is possible, however, to query the database using backend code when using suppressAuth: true in your query options. Keep in mind you will not be able to data bind the results data and will have to use code - but yes, it’s possible.”
So, it looks like I need to do some research on queries and this suppressAuth function - links to any useful documentation would be very welcome!