Please help with input values

I am a teacher creating a website to monitor student engagement.

When the page loads it pulls the names of my sample students from a collection called AllStudents. It places each student’s name in a form. Each teacher can complete the form and then send the information to another collection called TheProcess1.

I can successfully load the names onto the page but I can not get those same names into the second collection. I have pasted code below. Any help is appreciated

// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import {local} from 'wix-storage';


$w.onReady(function (){
	var sameChosenCluster = local.getItem("Pick")
	var sameSelectedGroup = local.getItem("Select")

	$w('#clusterName').text = sameChosenCluster;
	$w('#groupName').text = sameSelectedGroup;

	$w('#dataset2').onReady(function (){

	wixData.query("AllStudents")
	.eq("cluster", $w('#clusterName').text)
	.and(wixData.query("AllStudents")
	.eq("group", $w('#groupName').text))
	.find()
	.then((res) => {
		let items = res.items;
		let numItems = res.items.length;
		let a = 0
		let b = 0

		console.log("query completed")
		
		for (a = 0; a <numItems; a++)
		{
			$w('#studentName'+(a+1)).value = items[b].studentName;
			b++ 
		}

		for (a = 0; numItems + 1 < 16; a++)
		{
			$w('#box'+(numItems + 1)).collapse();
			numItems++
		}
		
	})// ends the results 		

	})// ends the data onReady

})//ends the page onReady




export function submitButton_click(event) {

//Add your code for this event here:

let student1 = {

"studentName": $w('#studentName1').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints1').value,

"respectPoints": $w('#respectPoints1').value,

"icPoints": $w('#icPoints1').value,

"engagePoints": $w('#engagePoints1').value,

"dTotalPoints": $w('#dTotalPoints1').value

};

let student2 = {

"studentName": $w('#studentName2').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints2').value,

"respectPoints": $w('#respectPoints2').value,

"icPoints": $w('#icPoints2').value,

"engagePoints": $w('#engagePoints2').value,

"dTotalPoints": $w('#dTotalPoints2').value

};

let student3 = {

"studentName": $w('#studentName3').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints3').value,

"respectPoints": $w('#respectPoints3').value,

"icPoints": $w('#icPoints3').value,

"engagePoints": $w('#engagePoints3').value,

"dTotalPoints": $w('#dTotalPoints3').value

};

let student4 = {

"studentName": $w('#studentName4').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints4').value,

"respectPoints": $w('#respectPoints4').value,

"icPoints": $w('#icPoints4').value,

"engagePoints": $w('#engagePoints4').value,

"dTotalPoints": $w('#dTotalPoints4').value

};

let student5 = {

"studentName": $w('#studentName5').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints5').value,

"respectPoints": $w('#respectPoints5').value,

"icPoints": $w('#icPoints5').value,

"engagePoints": $w('#engagePoints5').value,

"dTotalPoints": $w('#dTotalPoints5').value

};

let student6 = {

"studentName": $w('#studentName6').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints6').value,

"respectPoints": $w('#respectPoints6').value,

"icPoints": $w('#icPoints6').value,

"engagePoints": $w('#engagePoints6').value,

"dTotalPoints": $w('#dTotalPoints6').value

};

let student7 = {

"studentName": $w('#studentName7').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints7').value,

"respectPoints": $w('#respectPoints7').value,

"icPoints": $w('#icPoints7').value,

"engagePoints": $w('#engagePoints7').value,

"dTotalPoints": $w('#dTotalPoints7').value

};

let student8 = {

"studentName": $w('#studentName8').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints8').value,

"respectPoints": $w('#respectPoints8').value,

"icPoints": $w('#icPoints8').value,

"engagePoints": $w('#engagePoints8').value,

"dTotalPoints": $w('#dTotalPoints8').value

};

let student9 = {

"studentName": $w('#studentName9').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints9').value,

"respectPoints": $w('#respectPoints9').value,

"icPoints": $w('#icPoints9').value,

"engagePoints": $w('#engagePoints9').value,

"dTotalPoints": $w('#dTotalPoints9').value

};

let student10 = {

"studentName": $w('#studentName10').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints10').value,

"respectPoints": $w('#respectPoints10').value,

"icPoints": $w('#icPoints10').value,

"engagePoints": $w('#engagePoints10').value,

"dTotalPoints": $w('#dTotalPoints10').value

};

let student11 = {

"studentName": $w('#studentName11').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints11').value,

"respectPoints": $w('#respectPoints11').value,

"icPoints": $w('#icPoints11').value,

"engagePoints": $w('#engagePoints11').value,

"dTotalPoints": $w('#dTotalPoints11').value

};

let student12 = {

"studentName": $w('#studentName12').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints12').value,

"respectPoints": $w('#respectPoints12').value,

"icPoints": $w('#icPoints12').value,

"engagePoints": $w('#engagePoints12').value,

"dTotalPoints": $w('#dTotalPoints12').value

};

let student13 = {

"studentName": $w('#studentName13').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints13').value,

"respectPoints": $w('#respectPoints13').value,

"icPoints": $w('#icPoints13').value,

"engagePoints": $w('#engagePoints13').value,

"dTotalPoints": $w('#dTotalPoints13').value

};

let student14 = {

"studentName": $w('#studentName14').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints14').value,

"respectPoints": $w('#respectPoints14').value,

"icPoints": $w('#icPoints14').value,

"engagePoints": $w('#engagePoints14').value,

"dTotalPoints": $w('#dTotalPoints14').value

};

let student15 = {

"studentName": $w('#studentName15').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints15').value,

"respectPoints": $w('#respectPoints15').value,

"icPoints": $w('#icPoints15').value,

"engagePoints": $w('#engagePoints15').value,

"dTotalPoints": $w('#dTotalPoints15').value

};

let student16 = {

"studentName": $w('#studentName16').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints16').value,

"respectPoints": $w('#respectPoints16').value,

"icPoints": $w('#icPoints16').value,

"engagePoints": $w('#engagePoints16').value,

"dTotalPoints": $w('#dTotalPoints16').value

};

let student17 = {

"studentName": $w('#studentName17').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints17').value,

"respectPoints": $w('#respectPoints17').value,

"icPoints": $w('#icPoints17').value,

"engagePoints": $w('#engagePoints17').value,

"dTotalPoints": $w('#dTotalPoints17').value

};

let student18 = {

"studentName": $w('#studentName18').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints18').value,

"respectPoints": $w('#respectPoints18').value,

"icPoints": $w('#icPoints18').value,

"engagePoints": $w('#engagePoints18').value,

"dTotalPoints": $w('#dTotalPoints18').value

};

let student19 = {

"studentName": $w('#studentName19').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints19').value,

"respectPoints": $w('#respectPoints19').value,

"icPoints": $w('#icPoints19').value,

"engagePoints": $w('#engagePoints19').value,

"dTotalPoints": $w('#dTotalPoints19').value

};

let student20 = {

"studentName": $w('#studentName20').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints20').value,

"respectPoints": $w('#respectPoints20').value,

"icPoints": $w('#icPoints20').value,

"engagePoints": $w('#engagePoints20').value,

"dTotalPoints": $w('#dTotalPoints20').value

};

let student21 = {

"studentName": $w('#studentName21').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints21').value,

"respectPoints": $w('#respectPoints21').value,

"icPoints": $w('#icPoints21').value,

"engagePoints": $w('#engagePoints21').value,

"dTotalPoints": $w('#dTotalPoints21').value

};

let student22 = {

"studentName": $w('#studentName22').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints22').value,

"respectPoints": $w('#respectPoints22').value,

"icPoints": $w('#icPoints22').value,

"engagePoints": $w('#engagePoints22').value,

"dTotalPoints": $w('#dTotalPoints22').value

};

let student23 = {

"studentName": $w('#studentName23').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints23').value,

"respectPoints": $w('#respectPoints23').value,

"icPoints": $w('#icPoints23').value,

"engagePoints": $w('#engagePoints23').value,

"dTotalPoints": $w('#dTotalPoints23').value

};

let student24 = {

"studentName": $w('#studentName24').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints24').value,

"respectPoints": $w('#respectPoints24').value,

"icPoints": $w('#icPoints24').value,

"engagePoints": $w('#engagePoints24').value,

"dTotalPoints": $w('#dTotalPoints24').value

};

let student25 = {

"studentName": $w('#studentName25').value,

"date": $w('#date1').value,

"class": $w('#class1').value,

"attendPoints": $w('#attendPoints25').value,

"respectPoints": $w('#respectPoints25').value,

"icPoints": $w('#icPoints25').value,

"engagePoints": $w('#engagePoints25').value,

"dTotalPoints": $w('#dTotalPoints25').value

};

let allStudents = [

student1,

student2,

student3,

student4,

student5,

student6,

student7,

student8,

student9,

student10,

student11,

student12,

student13,

student14,

student15,

student16,

student17,

student18,

student19,

student20,

student21,

student22,

student23,

student24,

student25

]

let activeStudents = []

let slot1 = $w('#box1')

let slot2 = $w('#box2')

let slot3 = $w('#box3')

let slot4 = $w('#box4')

let slot5 = $w('#box5')

let slot6 = $w('#box6')

let slot7 = $w('#box7')

let slot8 = $w('#box8')

let slot9 = $w('#box9')

let slot10 = $w('#box10')

let slot11 = $w('#box11')

let slot12 = $w('#box12')

let slot13 = $w('#box13')

let slot14 = $w('#box14')

let slot15 = $w('#box15')

let slot16 = $w('#box16')

let slot17 = $w('#box17')

let slot18 = $w('#box18')

let slot19 = $w('#box19')

let slot20 = $w('#box20')

let slot21 = $w('#box21')

let slot22 = $w('#box22')

let slot23 = $w('#box23')

let slot24 = $w('#box24')

let slot25 = $w('#box25')

let allSlots = [

slot1,

slot2,

slot3,

slot4,

slot5,

slot6,

slot7,

slot8,

slot9,

slot10,

slot11,

slot12,

slot13,

slot14,

slot15,

slot16,

slot17,

slot18,

slot19,

slot20,

slot21,

slot22,

slot23,

slot24,

slot25

]

let activeSlots = allSlots.filter(a => a.isVisible === true)

let inactiveSlots = allSlots.filter(a => a.isVisible === false)

if (activeSlots.includes(slot1)) { activeStudents.push(student1) }

if (activeSlots.includes(slot2)) { activeStudents.push(student2) }

if (activeSlots.includes(slot3)) { activeStudents.push(student3) }

if (activeSlots.includes(slot4)) { activeStudents.push(student4) }

if (activeSlots.includes(slot5)) { activeStudents.push(student5) }

if (activeSlots.includes(slot6)) { activeStudents.push(student6) }

if (activeSlots.includes(slot7)) { activeStudents.push(student7) }

if (activeSlots.includes(slot8)) { activeStudents.push(student8) }

if (activeSlots.includes(slot9)) { activeStudents.push(student9) }

if (activeSlots.includes(slot10)) { activeStudents.push(student10) }

if (activeSlots.includes(slot11)) { activeStudents.push(student11) }

if (activeSlots.includes(slot12)) { activeStudents.push(student12) }

if (activeSlots.includes(slot13)) { activeStudents.push(student13) }

if (activeSlots.includes(slot14)) { activeStudents.push(student14) }

if (activeSlots.includes(slot15)) { activeStudents.push(student15) }

if (activeSlots.includes(slot16)) { activeStudents.push(student16) }

if (activeSlots.includes(slot17)) { activeStudents.push(student17) }

if (activeSlots.includes(slot18)) { activeStudents.push(student18) }

if (activeSlots.includes(slot19)) { activeStudents.push(student19) }

if (activeSlots.includes(slot20)) { activeStudents.push(student20) }

if (activeSlots.includes(slot21)) { activeStudents.push(student21) }

if (activeSlots.includes(slot22)) { activeStudents.push(student22) }

if (activeSlots.includes(slot23)) { activeStudents.push(student23) }

if (activeSlots.includes(slot24)) { activeStudents.push(student24) }

if (activeSlots.includes(slot25)) { activeStudents.push(student25) }

wixData.bulkInsert("TheProcess1", activeStudents)

.then((results) => {

let inserted = results.inserted;

let insertedIds = results.insertedItemIds;

let updated = results.updated;

let skipped = results.skipped;

let errors = results.errors;

dataset1_afterSave();

})

.catch((err) => {

let errorMsg = err;

dataset1_error();

});

}

Based on my understanding of your code, it loads students using a dataset and then filters them using a query (alternatively to using a Dataset Filter) according to groups and clusters to decide which ones get displayed on the page.

Then, you use the static event handler to get the “active slots” and push the associated students to an array for bulk insertion.

As I cannot spot the error immediately, I would investigate by seeing if the activeStudents array is correctly formatted for the bulk insert with the correct reference field titles associated to the collection.

Let me know what you find! :slightly_smiling_face: