wixData.insertReference() not working with single reference field

Tested and success!


export function buttonSaveClose_click(event, $w) {
//run validation
if (!validateFields()) {
return ;
}

// get the data from the dataset current item (easier to do than creating and tracking an object myself)

let currentItemObj = $w(‘#datasetDriversLicenseInfo’).getCurrentItem();
console.log(currentItemObj);

//add the referenced item by adding a new field to the copied object and providing the reference value

currentItemObj.driverReference = wixWindow.lightbox.getContext(); 
console.log(currentItemObj); 

//MANUALLY save the data (not using the dataset but using wixData)

wixData.insert('DriverLicenseInformation', currentItemObj) 
    .then(() => console.log('save succeeded'), ) 

}// tested and works so far!
//TODO: local error handling
//TODO: notification to calling function so data refreshes can happen if need be. use the lightbox close passing mechanism
//TODO: udate layouts for cleaner workflow and more advanced validations