Lightboxes: how to get the originating page ID?

Hi I have a lightbox that i use to add comments to a post, and is opened by clicking on a button in the post’s dynamic single item page. When i write the comment in the ‘comments’ database, i want to store the ‘originating page’ (meaning, the page from which i opened the lightbox) in the database field ‘Originating page ID’.

As of now, the ‘insert’ code in my lightbox is as follow:

let toInsert = {
commenterId: $w('#dataset1').getCurrentItem()._id,
commenterImage: $w('#dataset1').getCurrentItem().profileImage,
commenterName: $w('#dataset1').getCurrentItem().fullName,  
comment: $w('#comdatasetwrite').getCurrentItem().comment,
_createdDate: $w('#comdatasetwrite').getCurrentItem()._createdDate,  
}

wixData.insert("comments", toInsert)

.then( (results) => {
let item = results; 
console.log("OK")

Where the 2 datasets are the ones used to connect to the userProfile database (dataset1) and Comments database (comdatasetwrite).
I wonder if there is a way to add a row with something like this

originatingPostID: ...... //(something goes here - i bet it must connect to the userPosts dataset?),

Anyone can suggest a solution?
Thank you in advance

Hopefully I understand you correctly…

You can get the page you are on by using the Wix Location path() function.
If you’re on a dynamic page, then you can get the dynamic page’s prefix() , and then get the path() .

You can then pass these details to your Lightbox.

Thanks Yisrael… probably using the path and prefix can be a solution too… although i would have liked to store the page ID because later i will need to filter (i want to make sure that every single-post page only lists its own comments).
By the way, once i have gathered the data (path, prefix, etc…) how do i pass them to the lightbox? I though that the lightbox was some kind of ‘overlay’ which allowed me to act also on the page that originates it, instead they are completely different and isolated entities. What code would i use to pass data from the originating page to the lightbox?

@ademontis See how to pass data to a Lightbox in the openLightbox() API.

If you’re using this on dynamic pages, then it’s quite easy. A dynamic page has a dynamic dataset. Just get the current item of the page’s dynamic data set using the getCurrentItem( ) function. The data returned from this function will contain the unique information that helped create this dynamic page.

@yisrael-wix Thank you very much, you pointed me in the good direction. I was able to do it connecting a text to the dataset and retrieving the ID field. Then i pass it in a local variable:

export function image16_click(event) {
 let postId = $w('#text49').text; //this label is connected to the read only dataset in the userPosts database - field: Id
    wixWindow.openLightbox('CommentNew', {id: postId});
    local.setItem("postId", postId);
    console.log(postId)
}

Then, in the CommentNew lightbox, i can retrieve the local variable and use it in my text label.


$w.onReady(function () {
 let postId = local.getItem('postId');
    $w("#text50").text = postId; //this label is conneected to the write only dataset in the Comments database - field: originatingPostId

});

Thanks a lot, you made my day!