Pulling Data From Reference Fields via Javascript

Hey guys,
I have a main database that references other databases. I access this database to dynamically display information and media on a webpage.

I know that you can access a field by doing:
$w(“#dataset1).getCurrentItem()[”"];
Is there a way to do that with references?

Example: $w("#dataset1).getCurrentItem()[“projects”][“projectLanguage”];

If not, do you have any suggestions on how I may achieve something similar to it?

Thanks.

Hi,
Lets say that you have a dynamic page, you can get the _id attribute of the current item:

$w.onReady(function () {	
	let currentItem = $w("#dynamicDataset").getCurrentItem();
	let refID = currentItem.fieldName._id;	
}

Afterwards, you can use the get function to get the relevant record from the referenced collection.

Good luck!
Tal.

Cheers. I found that out about 30 mins ago. :stuck_out_tongue:
The only reason I found that was because I used Chrome’s Developer Console rather than Wix’s.
Wix = ‘ref’
Chrome = ‘_id’
I appreciate the help though Tal :slight_smile:

1 Like