Get Dynamic-Page-ID into Data-Table

Hey Guys,

i created a dynamic page template with the option to submit data on it AND display it on the same page directly (through the filter option).

To get the matching data after sending my custom form, i need the end of the Dynamic-Page-URL as Data in my table.

import wixLocation from 'wix-location';
$w.onReady(function () {
$w("#dataset2").onBeforeSave(function() {
    $w("#dataset2").setFieldValue('ean', wixLocation.query);
});
});

My code only gives me [object Object] in the data table backā€¦

Have a read of setFieldValue and Location Query
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValue
https://www.wix.com/corvid/reference/wix-location.html#query

Read other previous posts too.
https://www.wix.com/corvid/forum/community-discussion/parse-url-to-get-a-parameter
https://www.wix.com/corvid/forum/community-discussion/wixlocation-to-get-and-use-http-query

Hey,

thank you for the fast answer - but i already read some of those.
I cant find the error.

With all 3 codes i just get [object Object]

1. My first Code

import wixLocation from 'wix-location'; 

$w.onReady(function () { $w("#dataset2").onBeforeSave(function() { $w("#dataset2").setFieldValue('ean', wixLocation.query); $w ("#dataset2"). save () });
  1. Second Code (fixed loading)
import wixLocation from 'wix-location'; 

$w.onReady( () => { $w("#dataset2").onReady( () => { $w("#dataset2").setFieldValue("ean", wixLocation.query); $w ("#dataset2"). save () } ); } );
  1. Third Code (New "Trigger)
import wixLocation from 'wix-location';

export function button1_click(event) {
 //Add your code for this event here: 
    $w("#dataset2").setFieldValue("ean", wixLocation.query);
   $w ("#dataset2"). save ()
}

You missing out code.

import wixLocation from 'wix-location';

// ...

let query = wixLocation.query;

You need to tell the code that you want to query and what, see here for a great example.
https://www.wix.com/corvid/forum/community-discussion/using-wixlocation-query-results-items

Then you will have a value to use with the setFieldValue call which you can save to your dataset.

Although the example here should have been clear enough.
https://www.wix.com/corvid/forum/community-discussion/wixlocation-to-get-and-use-http-query