I need to solve "wix location is not defined" error. (Trying to link a column to an internal page)

This what is currently have written

export function functionalmolding_click(event) {
 //Add your code for this event here: {
    wixLocation.to("https://www.smpco.com/functional-molding",)
}


And here is my properties panel

Add in import statement to the beginning of your code file:

import wixLocation from 'wix-location';

I did this but the statement immediately greys out in the editor and the code then doesn’t function. If I don’t put this in then I get an error that wixLocations is undefined when I try to reference it using the to property as the original poster above.

Hey Tom,

Copy paste your code here so that we can take a look and see the issue in order to help you out.

Thanks Pratham,
I have resolved the to problem by using

import wixLocationFrontend from “wix-location-frontend”;

at the top of my code and then using

wixLocationFrontend.to(fully qualified link here)

in the body of the code. This code now works as desired.

However I’m now trying to pull one field from the current item on a dynamic page. When the line of code that tries to pull the single field

dbpwout1 = $w(“#ToursItem”).getCurrentItem().Tour-Password;

is uncommented NOTHING works. If I comment it then everything runs but obviously I don’t get the desired result returned, it returns the null I set it to at the beginning of the function. I’ve tried many different avenues to do this, some resulted in imports killing the code. This is the final try that got closest. What am I missing?

Here is an example of the code:
function GetPassword1 (tourID)
{
let dbpwout1 = “”;
TraceMessage(“In GetPassword 1 about to get object”);
dbpwout1 = $w(“#ToursItem”).getCurrentItem().Tour-Password;

	TraceMessage("Got the DB Password " + dbpwout1);

	return dbpwout1;
} // End GetPassword1 Function

The issue is related to the way the data is being accessed. I imagine this .Tour-Password; is showing an error.

You’re probably best doing something like:

let itemObj = $w("#ToursItem").getCurrentItem()
let tourPassword =itemObj["Tour-Password"]

Then you can use tourPassword wherever you need it

Thanks Noah, I had already done the following before seeing your post:

function GetPassword ()
{
let dbpwout = “”;
let itemObj = $w(“#dynamicDataset”).getCurrentItem();
dbpwout = itemObj.tourPassword; //get the relevant field key

	TraceMessage ("The PW in the DB is "+ dbpwout);

	return dbpwout;

This function works just fine. Thank you for your reply and help!

Tom

1 Like