Concatenate Fields Before Insert

import wixData from ‘wix-data’;

export function ProductsServices_beforeInsert(item) {
const fieldValue1 = item.makeNew; // Replace ‘field1’ with the name of your first field
const fieldValue2 = item.model; // Replace ‘field2’ with the name of your second field
// Concatenate the values
const concatenatedValue = fieldValue1 + " " + fieldValue2; // You can adjust the concatenation as needed
// Update the item with the concatenated value before inserting it into the collection
item.makeModel = concatenatedValue; // ‘concatenatedField’ is the name of the field where the concatenated value will be stored
return item;
}

let item = {
make: “make”,
model: “model”,
makeModel: “”
}

item = ProductsServices_beforeInsert(item)

console.log(item)

can you show me the WHOLE code including the writing to the collection and other stuff

that is all I have. I have no more code. I am editing the collection by editing directly in the collection

can you show me the console

sorry - I don’t know what a console is.

I am brand new (started on Sunday) to Wix, Velo and Java. I have no experience.

are you in the preview mode or production?

I am designing the site and occasionally view in Preview mode just to see what it looks like

what does it write in there

I have “export function” but you just have “function”

sooo if you are going to use that method you need to fill the item in the left on your screenshot it needs to be like this:

{
    item : {
        make: "make",
        model: "model",
        makeModel: ""
    }
}

the “export” is for accessing the function from another file

So sorry, where do I add this code ?


here

I seem to have errors

i forgot the "
fixed version:

{
    "item" : {
        "make": "make",
        "model": "model",
        "makeModel": ""
    }
}

No - still not working.

I don’t think we are going to fix this.

so you are running only the function by this if you wanna se an output use the console.log inside the function

Error loading web module backend/data.js:
e[31mxe[0m Expected ‘;’, ‘}’ or
,-[e[36;1;4mbackend/data.jse[0m:17:9]
e[2m17e[0m | model: “model”,
: e[31;1m ^e[0m
`----

Error:
e[36m>e[0m This is the expression part of an expression statement
,-[e[36;1;4mbackend/data.jse[0m:16:9]
e[2m16e[0m | e[31;1m,e[0me[31;1m-e[0me[31;1m>e[0m make: “make”,
e[2m17e[0m | e[31;1me[0me[31;1m-e[0me[31;1m>e[0m model: "model", ----

Caused by:
0: failed to process input file
1: Syntax Error
Error loading web module backend/data.js:
e[31mxe[0m Expected ‘;’, ‘}’ or
,-[e[36;1;4m/user-code/backend/data.jse[0m:17:9]
e[2m17e[0m | model: “model”,
: e[31;1m ^e[0m
`----

Error:
e[36m>e[0m This is the expression part of an expression statement
,-[e[36;1;4m/user-code/backend/data.jse[0m:16:9]
e[2m16e[0m | e[31;1m,e[0me[31;1m-e[0me[31;1m>e[0m make: “make”,
e[2m17e[0m | e[31;1me[0me[31;1m-e[0me[31;1m>e[0m model: "model", ----

Caused by:
0: failed to process input file
1: Syntax Error

I am so sorry, but I am really confused now. Could you tell me what the whole code in beforeinsert should look like please ?

I seem to have several errors