Hi all. I have a list of records - submitted reports. Each record does not have an intrinsically unique identifier except for the ones generated by Wix. I created a list page with a table and six fields and would like the user to be able to click on one of those fields to bring up a dynamic page which has the complete content of the selected reports.
Ideally I would like to define the dynamic page by using the created date since that will always be unique, but when I go to link the page to the collection that field is unavailable. So … the next obvious choice was ID. I selected that and sure enough a URL field was added to the collection showing the ID. So far, so good.
That is, until I went back to the list page and attempted to link one of the fields to the URL (DGReport(ID)). Even though on the collection (I both synced and published first) I see the field of type URL, when I attempt to link to that field it’s not in the list of available fields.
I’m sure there’s an obvious solution I’m overlooking, but I couldn’t find a similar use case via forum search. Any and all thoughts and suggestions welcomed.
Thank you,
Scott
Hi Scott!
Item ID and _ownerID are two fields that are created automatically upon item submission to the collection (you can see them under ‘Visible Fields’ in the collection page).
The value of itemID is unique and so - two items will never have the same ID.
About the _ownerID - it is also unique but since it represents the ID of the user who created the item, if there’s no limitation on how many items/records can a user create, there may be more than one.
When talking about profile page/user page we obviously want to limit it.
Using the WixUsers API and specifically the wixUsers.currentUser you can obtain the user’s ID.
Note that this ID is not the ID of the data item that is stored in your collection and that you’re wanting to retrieve. This ID is the serial number of the user that created it and you can use it to retrieve the correct data item from the collection. (basically wixUsers.currentUser.id = _ownerID).
Now, In order to navigate to one’s dynamic item page you’ll need to find the correct path to follow.
It 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.to('/yourPath/${url}')
}
})
}
Hope that helps!
Doron.
Hi Doron,
Thanks for the helpful suggestion, but in this simple use case there’s a snag - I’m not asking for specific users to log in before accessing the page with the list of reports. It’s a hidden page (not in the menu) - if I need to I can set up a login since only a handful of users in the main office will have access to this view.
Is that the only alternative? There’s no other way to retrieve the item ID?
Scott
This is great. Thanks. One question though can (‘/yourPath/${url}’) be defined by the unique ID of a collection row? and if so how
Thanks and Regards
Adam
sir please tell me how to link email address from data base to dynamic page
How can I get the dynamic page ID? By choosing the Link ID on the collection?