Get receipt and bill internal ids of purchase order using Suitescript.

let poRecord = record.load({
    type: record.Type.PURCHASE_ORDER,
    id: '<purchaseorderinternalid>',
    isDynamic: true,
});
let relatedRecords = {
    'irArray': [],
    'billArray': []
};
let numLinesIR = poRecord.getLineCount({
    sublistId: 'links'
});
for (let i = 0; i < numLinesIR; i++) {
    let type = poRecord.getSublistValue({
        fieldId: 'type',
        sublistId: 'links',
        line: i
    });
    if (type === 'Item Receipt') {
        let receiptId = poRecord.getSublistValue({
            fieldId: 'id',
            sublistId: 'links',
            line: i
        });
        relatedRecords.irArray.push(receiptId);
    } else if (type === 'Bill') {
        let billId = poRecord.getSublistValue({
            fieldId: 'id',
            sublistId: 'links',
            line: i
        });
        relatedRecords.billArray.push(billId);
    }
}

Leave a comment

Your email address will not be published. Required fields are marked *