Help

Wrong input records pulled? Help

Topic Labels: Scripting extentions
961 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Go_Ask_Nick
4 - Data Explorer
4 - Data Explorer

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.

Screenshot 2021-02-23 at 8.03.25 PM

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

Screenshot 2021-02-23 at 8.05.21 PM

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
});
0 Replies 0