Wix Location with a Dynamic page

Hello guys, i have got a problem with wixlocation and dynamic page,i can’t enter the page because i wrong something.so when i push a button, it should send me to a member page(dynamica page).

export function button62_click(event) {
wixLocation.to(‘/profilo/${wixUsers.currentUser.id}’);
}

Hi @fraspace5 !

Note that when you navigate to “${wixUsers.currentUser.id}” you send as a parameter the ID of the current user , while usually, dynamic pages are based on a field (an ID in this case) of an item in the collection.
Basically the phrase you use indicates the owner ID of an item but what you should do is to query this phrase and return the item ID of the matching item with this value (“${wixUsers.currentUser.id}”) as _owner.

Let me know if it works for you!

Doron.

@doron-alkalay
I didn’t understand very well, so what code should i add?

@fraspace5 instead of navigating to the user’s ID (which is actually the ‘_owner’ in your collection) - look for the item he owns in your collection and navigate to that item’s ID.

Should look something like this:

if (wixUsers.currentUser.loggedIn) {
     wixData.query("yourCollection")
            .eq("_owner", wixUsers.currentUser.id)
            .find()
            .then((results) => {
               if (results.length > 0) {
                   let url = results.items[0].id ;
                   wixLocation.to('/profilo/${url}')
                }
            })
    }

If it is not working for you please share a link to your site so one of us, the Wix Code team, can inspect it and provide you with a solution.

Doron.

@doron-alkalay I don’t know but it doesn’t works, https://laram24.wixsite.com/laram

@fraspace5
Can you please guide me through your site?
How Items are being created to the “Account” collection?
In which page does the submission occurs?
Please elaborate as much as you can on the flow of Account-creating in your site.

Doron.

@doron-alkalay
Well, items go to the Account Collection when you register yourself in the site,(click on the button ‘Entra’ at the top of the homepage.
I have to go to the dynamic page when i click on the button called ‘Tasto’, always at the top of the Homepage.Thanks.The language is Italian.

Hi @fraspace5 !

I’ve seen in your database some items that were created without value in the ‘_owner’ field.
This seems to be the reason to cause the query no to work but in order to help you overcome it we’ll need to understand why these items were created that way.

Please try to recreate your steps and provide a detailed sequence of events (and screenshots/screencast) that leads to this state.

Doron.

@doron-alkalay
Ok,i will do it, but at the moment I can’t because he gives me an error (error 500 ) when I submit the register request,can you see it?

@fraspace5 I’ve managed to submit items to your ‘Account’ Database and recreate the issue of no value in the ‘_Owner’ field.
Our QA team is on it and I’ll update this thread as soon as it is resolved.

Doron.

@doron-alkalay Thank you so much!!

@doron-alkalay Did you find a solution?

@fraspace5 Hey!
After a checkup by our QA team we concluded that the lack of “_owner” value is caused by submission of users of type ‘guest’ which means that they do not have a static ID and every item that is created by them lacks the value in this field.

Please check the method with which you log in your user and make sure that the user is recorded in your site’s collection/member list (Data/Dashboard).
If the issue persists I’d suggest that you’ll add the user ID semi-‘manually’ - add the wixUsers.currentUser.ID as the value of the “_owner” field.

Doron.

@doron-alkalay Thanks,so what should I change?
Should I change the method to accept members?

@fraspace5 Not sure if you have to change the entire thing, just need to verify that the user record is indeed created and that the item in the collection is valid.
If you’re having troubles with it I’d suggest you to look into one of these articles/guides:

Create A Member Profile Log In Page - Custom Client or Member Dashboard - Wix Code Tutorial
Wix Code Tutorial: Building Your Own Members Area
HELP! Custom Member Login - Prompt Username & Password

Hope that will help you set things right.

Doron.

@doron-alkalay Ok, it doesn’t works so I want to do this:
If the issue persists I’d suggest that you’ll add the user ID semi-‘manually’ - add the wixUsers.currentUser.ID as the value of the “_owner” field.
But I can’t customize the _owner field I think.

@fraspace5 You don’t have to use this specific field.
You can create one of your own and rely on that. :slight_smile:

@doron-alkalay Look if this is correct : let user = wixUsers.currentUser;

let userId = user.id; // “r5cme-6fem-485j-djre-4844c49”

let toUpdate = {
“_proprietario”: userId,
};

            wixData.update("account", toUpdate) 
                .then((results3) => { 

let item = results3; //see item below
})
. catch ((err) => {
let errorMsg = err;
});

@fraspace5 You need to add a matching field in the collection in order for it to work and to update the userId to this field.
Think of it as a field that represents the serial number of your user.

Doron.

@doron-alkalay Hi, i don’t know but this code doesn’t workout doesn’t set the field value _proprietario as the id of the user.Thanks