I saw I’m not the first one that insertReference didn’t insert correct data into collection.
So finally I succeed doing so with DataSet item:
$w( “#MyDataSet” ). new ()
.then( ( ) => {
console.log( “New item created” );
$w( “#MyDataSet” ).setFieldValues( {
“date” : $w( ‘#dateBuyingNewItem’ ).value,
“Name” : $w( ‘#inpName’ ).value,
// This is my reference field, when loaded the drop down component I already loaded the items ID as the Value property of each item
“dealer” : $w( ‘#dropDownDealer’ ).value
} );
$w( “#MyDataSet” ).save();
} )
. catch ( (err) => {
let errMsg = err;
} );
That’s it!
The only problem is that the screen is flickering twice, since the data set is refreshing twice: once when DataSet.New command is saving the last item, second when DataSet.Save command is called.