Mmm...I need your help!
In that convo I was successful in writing a script to link records in a one-to-many relationship. But what I actually need to do is process three Access tables related as follows:
Items
itemid
attachmentid
itemname
Attxref
itemid
attachmentid
Attachments
attachmentid
filename
One record in ITEMS will have many records in ATTXREF, and one record in ATTACHMENTS will also have many records in ATTXREF.
I have created two libraries in Memento:
Main
Itemid
Itemname
Attachments (link-to-entry field, many-to-many to mmAttachments)
Home Inventory Attachments
Itemid
Attachmentid
Home Inventory Attachments Xref
Attachmentid
Filename
The mmAttxref library is only needed temporarily to run the script and populate the link-to-field column Attachments in mmItems.
From previous examples you provided, I got as far as creating a filtered array of records from Home Inventory Attachments Xref for an Itemid in Main. But my knowledge and experience with javascript is limited, and I can't seem to figure out how to create a filtered array of Home Inventory Attachments records and populate the Attachments column in Main.
Below is what I have so far and I know works. I looked at push() and other methods, but could not figure it out. I am hitting my head against the wall, so any help you can provide is appreciated.
Thanks for your help...
Doris
*******************
let main = selectedEntries();
let att = libByName('Home Inventory Attachments').entries();
let xref = libByName('Home Inventory Attachments Xref').entries();
let finditem = '';
let findatt = '';
let mainfilter = [];
let attfilter = [];
let xreffilter = [];
let i = main.length; // number of selected entries in Main library
//message('Number of Items: ' + i);
while (i--) {
finditem = main[i].field('ItemID'); // get ItemID for record in Main
if (finditem > 0 && !main[i].field('Linked')) { // check if the record has been linked
message('Processing ItemID ' + finditem);
xreffilter = xref.filter(a => a.field('ItemID') === finditem); // get the related attachment xref records
let j = xreffilter.length;
message('Number of attachments in xref: ' + j);
while (j--) {
findatt = xreffilter[j].field('AttachmentID'); // get AttachmentID for first selected record in xref
message('Processing AttachmentID: ' + findatt);
if (findatt > 0) {
attfilter = att.filter(a => a.field('AttachmentID') === findatt); // get the related attachments record
message('Numbrt of attachment records found: ' + attfilter.length);
// THIS IS WHERE I GET STUCK :(
}
}
}
}