I am trying to set a field value and save it to the data collection. the field (FK_Type_Id) is set before the save and then is loses it’s value and doesn’t get passed into the saved record… see console output below. What am I doing wrong? I have tried everything.
[itemValuesChanged event] triggered on wix-dataset with ( {" recordBeforeChange “:{“prayerDate”:“2018-07-26T04:00:00.000Z”,“description”:“h”,“title”:“h”,“isPublic”:true,”_id":“524526c5-b162-4bab-a632-72b72d0bdc2c”,“User_Userid”:“0bc89b37-4386-4b83-bcbc-3c91f0cf3e6e”," FK_Type_Id":“ab1e9ffb-37b3-474d-a92d-ab298945beb8” }," recordAfterChange “:{“prayerDate”:“2018-07-26T04:00:00.000Z”,“description”:“h”,“title”:“h”,“isPublic”:true,”_id":“524526c5-b162-4bab-a632-72b72d0bdc2c”,“User_Userid”:“0bc89b37-4386-4b83-bcbc-3c91f0cf3e6e”,“_owner”:“0bc89b37-4386-4b83-bcbc-3c91f0cf3e6e”,“_createdDate”:“2018-07-26T19:25:42.115Z”,“_updatedDate”:“2018-07-26T19:25:42.115Z”}} )
console.js:35 [afterSave event] triggered on wix-dataset with ( {" beforeSaveRecord “:{“prayerDate”:“2018-07-26T04:00:00.000Z”,“description”:“h”,“title”:“h”,“isPublic”:true,”_id":“524526c5-b162-4bab-a632-72b72d0bdc2c”,“User_Userid”:“0bc89b37-4386-4b83-bcbc-3c91f0cf3e6e”,“_owner”:“0bc89b37-4386-4b83-bcbc-3c91f0cf3e6e”,“_createdDate”:“2018-07-26T19:25:42.115Z”,“_updatedDate”:“2018-07-26T19:25:42.115Z”}," afterSaveRecord “:{“prayerDate”:“2018-07-26T04:00:00.000Z”,“description”:“h”,“title”:“h”,“isPublic”:true,”_id":“524526c5-b162-4bab-a632-72b72d0bdc2c”,“User_Userid”:“0bc89b37-4386-4b83-bcbc-3c91f0cf3e6e”,“_owner”:“0bc89b37-4386-4b83-bcbc-3c91f0cf3e6e”,“_createdDate”:“2018-07-26T19:25:42.115Z”,“_updatedDate”:“2018-07-26T19:25:42.115Z”}} )
console.js:35 [wix-dataset.save] returned with ( {“prayerDate”:“2018-07-26T04:00:00.000Z”,“description”:“h”,“title”:“h”,“isPublic”:true,“_id”:“524526c5-b162-4bab-a632-72b72d0bdc2c”,“User_Userid”:“0bc89b37-4386-4b83-bcbc-3c91f0cf3e6e”,“_owner”:“0bc89b37-4386-4b83-bcbc-3c91f0cf3e6e”,“_createdDate”:“2018-07-26T19:25:42.115Z”,“_updatedDate”:“2018-07-26T19:25:42.115Z”} )
Here is the code:
import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;
let user = wixUsers.currentUser;
let typeId = “testing”;
…
export function button1_click(event, $w) {
let typeName = $w(‘#dropdown1’).value;
$w("#dataset2").onReady(() => {
console.log("dataset is onReady...");
console.log('typeName: ' + typeName);
wixData.query("Type")
.eq('name', typeName)
.find() // Run the query
.then(results => {
let items = results.items;
let firstItem = items[0];
typeId = firstItem[‘_id’];
console.log('results in query function: ' + typeId);
setFields(typeId);
}). **catch** (error => {
console.log(error);
});
$w("#dataset2").setFieldValue("User_Userid", user.id);
function setFields(typeID) {
console.log(“before setFieldValue…” + typeID);
$w(‘#dataset2’).setFieldValue(“FK_Type_Id”, typeID);
}
});