Hi folks,
My brain is jelly, I can save each of these collections separately, but not both at the same time. What am I doing wrong?
Thanks for the help,
Sylvia
export function m1Checkbox_click(event) {
addClubName();
addStudentName();
}
function addClubName() {
//Club- get the current club's name from clubs-Registration (All)
let newClub = $w("#clubDetails").getCurrentItem().club;
console.log("get1 newClub from clubDetails = " + newClub); //works
//Clubs- get the current Club names from 1425MemberProfiles m1Clubs
let m1Clubs = $w("#1425MemberProfiles").getCurrentItem().m1Clubs;
console.log("get2 m1Clubs from 1425MemberProfile = " + m1Clubs); //works
//if the Clubs field is empty add the Club name to 1425MemberProfiles
if (m1Clubs === undefined) {
$w("#1425MemberProfiles").setFieldValue("m1Clubs", newClub);
console.log("set3 newClub to 1425MemberProfiles =" + newClub); //works
} else {
//if there are already Clubs in that field create an array and add this club to the end
const allClubsArray1 = [];
allClubsArray1.push(m1Clubs);
allClubsArray1.push(newClub + ", ");
const allClubsString = allClubsArray1.join(" ");
$w("#1425MemberProfiles").setFieldValue("m1Clubs", allClubsString);
console.log("set4 allClubsString to 1425MemberProfiles =" + allClubsString);
}
}
function addStudentName() {
//Student- get current student's name from PrivateMembersData
let m1Student = $w("#m1NameText").text;
console.log("get1 m1Student from userId = " + m1Student); //no
//Students- get current students names from Club Details
let studentNames = $w("#clubDetails").getCurrentItem().studentNames;
console.log("get2 studentNames from clubDetails = " + studentNames);
if (studentNames === undefined) {
$w("#clubDetails").setFieldValue("studentNames", m1Student + ", ");
console.log("set3 m1Student to clubDetails = " + m1Student); //works
} else {
//create an array and add the name to the end
const allStudentsArray1 = [];
allStudentsArray1.push(studentNames);
allStudentsArray1.push(m1Student + ", ");
const allStudentsString = allStudentsArray1.join(" ");
$w("#clubDetails").setFieldValue("studentNames", allStudentsString);
console.log("set4 allStudentsString to clubDetails =" + allStudentsString);
}
}
export function submitButton_click(event) {
$w("#1425MemberProfiles").save();
$w("#clubDetails").save();
$w("#success").show();
$w("#success").expand();
$w("#error").hide();
$w("#error").collapse()
.catch((err) => {
$w("#success").hide();
$w("#success").collapse();
$w("#error").show();
$w("#error").expand();
});
}