I’m trying to import data from JSON to my Collection. But when I review the collection, the data was created in new fields and not in the fields of the Collection. Example: The Collection has a field named Cliente, but the new data was imported to a new field named [Cliente].
I used this code:
export function importButton_click(event) {
const items = JSON.parse($w(“#textBox”).value);
const collection = $w(“#collectionInput”).value;
items.forEach( (item) => {
wixData.insert(collection, item)
.then( (results) => {
console.log(Added item: ${JSON.stringify(results)}
);
} )
. catch ( (err) => {
console.log(err);
} );
} );
$w(“#textBox”).value = “”;
}
Can you help me with this issue?
Thank you!
Arturo
Hello Arturo
would you please check the field’s key (Cliente or cliente), most probably that’s why your getting new fields as it’s not finding existing keys with the values.
and to fix this you have to make sure you use the fields keys not values:
I hope this helps!
Massa
Thank you Massa! The problem was resolved!
I have another question for you: My final purpose is that the information my page shows should be the data that I have in a SQL Server DB. And when I change this information in the page, I need that the data in SQL Server have to be updated.
To do this I think that the steps could be 1. The user writes the data in de page. 2. this data actualize a Collection DB. 3. The Collection DB Data is exported as a JSON file. 4. The SQL Server updates the table with this new data.
I’m new in WIX code, but I guess it could exist a simpler method to do this procedure.
What do you think?
Thank you,
Arturo
Hello Arturo,
For your first two steps, Follow this guide on how to get that set up here .
Next, you can make your site have API Request that return specific data from the collection in JSON format, to do that look at the documentation provided here . As for the last step, I am not sure what integration SQL provides with this so that is up to you to figure out.
Hope this helps,
Majd
Thank you Majd!
I’m going to review the links you sent me. But it looks that doesn’t exist a simpler method to update de SQL Server using WIX. I was looking to connect my WIX page with the SQL Server DB trying to avoid the need of using JSON files. Is it impossible?