Wrong input records pulled? Help

I have a ledger for tracking inventory movements.

When I create a new line with a 502 movement I want to run a script. The script has an input variable which is a list of linked records from another base.

I want to read those records and get some data from them and then automatically create some new lines in my ledger base.

I am trying to pass the values from the subcontracting records lookup

The problem is when I read the subcontracting records it looks like it is reading multiples of the same record ID and when it writes to my ledger it links the incorrect material codes. Can someone help me with what I am doing wrong?

//sets up the tables and input var
let subcontractingTbl = base.getTable('Subcontracting');
let ledgerTbl = base.getTable('Ledger');
let inputConfig = input.config();
let mapOutput = 0;
let compPosted = 0;



//loop thorugh, read the subcontracting components and writes to ledger
for (let i = 0; i < inputConfig.subcontractedRecord.length; i++) {
    let subconInput = inputConfig.subcontractedRecord[i];
    let subconResult = await subcontractingTbl.selectRecordsAsync();
    let subconRecord = subconResult.records[subconInput]
    let postedAmt = subconRecord.getCellValue('Component') * subconRecord.getCellValue("Component Quantity") * subconRecord.getCellValue("in (1) or out (-1) (from Movement Type)");

    //Writing the record
    //should this be createRecordsAsync?
    let subWrite = await ledgerTbl.createRecordAsync({
        "Material Master": subconRecord.getCellValue("Component"),
        "Entered Quantity": subconRecord.getCellValue("Component Quantity"),
        "Movement Type" :[{id: "recOcjn1gd2MjDGVL"}],
        "Description": "Automatic Issue for Subcontracted material",
        "Amount Posted": postedAmt
    });

    //adds amount of all componets to post for subcontracted material
    compPosted += postedAmt; 
};

//Update original ledger record with posted amount
let postedAmt2 = await inputConfig.ledgerRecord;
let subWrite = await ledgerTbl.updateRecordAsync(postedAmt2, {
    'Entered Amount $': compPosted,
    "Amount Posted": compPosted
});