Join value of column in child table and set value to field in parent document

Child table : SubItems
filed in child table: x

parent table: Item
field in parent table: y

I want to join all value of field “x” in child table and set the result on y field

the script which I tried but didn’t work as the following:

frappe.ui.form.on(“Item”, {
validate: function(frm) {
all = 0;

	$.each(frm.doc.SubItems|| [], function(i, d) {

		var items = (d.x); 
		var all = items.join(); 

	});
	frm.set_value("y", all);
}

});

Please help, thanks