[SOLVED]Problem regarding saving data in live collection

Hello Pronil,

Instead of declaring functions within functions, have them as top level functions so that you can call them and declutter your code and make it more managable.

Like so:

export function retireve_click(event, $w) {
    SaveDataToDatabase();
}

Remove all the other functions and just test the SaveDataToDatabase function first, make sure it is working correctly.

Then I see you want to do some sort of error checking so to do that, have it as a seperate function and put it in the SaveDataToDatabase function before you insert. (check for errors before inserting)

Like so:

if(errMessage == null){
	wixData.insert("SUMMARY", toInsert, options)
} else {
	$w('exampleText').text = errMessage
}

So in short, clean up your code, create a separate function for each functionality, test each function one at a time, and it should work.

Also use this button as it is really helpful :)!

Best,
Majd