Saving data to dataset with a code

Hi,
I would like to submit data to the database with the code (for some reasons I cannot use a button with a Submit function). I am trying the following structure:

$w(“#dataset1”).setFieldValue(“Field”, Value);
$w(“#dataset1”).save()

However it does not submit data to the database. How should I approach this?
Thank you in advance.

Hello konrad.kostrzewa,
this little piece of code should help you…

export function button2_click(event) {
    $w('#dataset1').setFieldValue("video", "xxxxxx")
    $w("#dataset1").save()
}

The action is fired by an click on the button called ----> “button2”.

$w('#dataset1').setFieldValue("video", "my new value")

Here you have the connection to yout dataset (in this example —> “dataset1”).
With this command you [sets] a [FieldValue] to a specific REFERENCE (“video”) with the new value (“my new value”) into your DATA-COLLECTION…

$w("#dataset1").save()

and then save it.

EDIT:


And if you would use the searchbar, i am sure you would also find some posts like this one…

…in this forum!

Or just take a look into the “Corvid-API-Reference” here…

Thanks. I tried that and it does not work :frowning: Do you have any idea why? There are no new records in the database after clicking on the button. I checked the database permissions as well

Is your dataset set to write only? Have you checked the logic of your form? For, example of set to read and write does the record exist before attempting to update it?

@code-queen the detaset is set or read & write for everyone. How do I check whether the record exists? I would like to create a new record

Hello Konrad,
if you are still looking for a solution, perhaps this post here can help you out.
I think it is very similar to your problem.
https://www.wix.com/corvid/forum/community-discussion/dynamic-page-onaftersave

Just take a look.

Hi Konrad,

This reference might help you. It definitely helped me with mine since I have the same problem as yours. Check it out:

https://www.wix.com/velo/reference/wix-dataset/dataset/save