Hi Victoria and apologies for the late response. I didn't get an email notification that there had been a response and haven't checked in here for a few days. Anyway, I did get this to work in the end but having the the trigger() inside the for loop makes it really slow so I have been trying to work on an alternative option which is:
var bundlestudy = new Array();
var bndl_id = tableBundles.selectedRow.data.id;
function runQuery (i) {
for (var i = 0; i < ListboxStudies.selectedItems.length; i++) {
var valueToPush = {};
var study_id = ListboxStudies.value[i];
valueToPush[0] = study_id;
valueToPush[1] = bndl_id;
bundlestudy.push(valueToPush);
//console.log('test',i, valueToPush[0], valueToPush[1], bundlestudy[0][i]);
}
}
runQuery(0)
await runQuery(0);
query116.trigger({
additionalScope: {
bundlestudy: bundlestudy,
},
});
bundlestudy.transposed = new Proxy(bundlestudy, {
get: (arr, col) =>
+col >= 0 ? new Proxy({ length: bundlestudy.length }, {
get: (obj, row) => +row >=0 ? arr[row][col] : obj[row]
})
: col == 'length' ? arr[0] && arr[0].length
: col == 'original' ? arr
: undefined
});
var t = bundlestudy.transposed;
await runQuery(0);
insertBundleStudy.trigger({
additionalScope: {
bundlestudy: t,
},
});
// This is the output of the transposed array:
console.log(t[0][0],t[1][0]) //1a603b0e-a37e-44df-95dc-dce3ad51ad82 10
console.log(t[0][1],t[1][1]) //6b043372-8668-443b-9033-3ddf838be37d 10
console.log(t[0][2],t[1][2]) //5c5378fc-05c6-4147-872d-6e2d4bc3324e 10
// This is the insertBundleStudy query using the GUI method:
{{ [{study_id:bundlestudy[0]}, {bundle_id:bundlestudy[1]}] }}
I thought by transposing the array from this structure [ [s1, t1 ] , [s2, t2 ] , [s3, t3] , [sn, tn ] ] to this structure [ [ s1, s2, s3, sn] where s i= study_id and t =bundle_id I could then reference the array using bundlestudy[0] and bundlestudy[1] but it produces the following:
" !error "insert into "admin"."bundle_study" ("bundle_id", "study_id") values (DEFAULT, $1), ($2, DEFAULT) - invalid input syntax for type uuid: "{"0":"1a603b0e-a37e-44df-95dc-dce3ad51ad82","1":10}".
If you could help with this I'd really appreciate it. Thanks in advance.