how to create sublist on vendor bill that lists al...
# ask-stanley-ai
n
how to create sublist on vendor bill that lists all related purchase order expense lines
c
AI generated answer (using internal Slack threads):
To create a sublist on a vendor bill that lists all related purchase order expense lines, you would need to use SuiteScript. Here's a general approach: 1. Create a User Event script that triggers on the creation or editing of a Vendor Bill record. 2. In the script, use the
record.load
method to load the Vendor Bill record. 3. Use the
record.getSublist
method to get the 'item' sublist from the Vendor Bill record. 4. Loop through each line in the 'item' sublist and use the
record.getSublistValue
method to get the values of the 'orderdoc' and 'orderline' fields. These fields link the Vendor Bill line to the corresponding Purchase Order line. 5. Use the
record.create
method to create a new custom record for each line in the 'item' sublist. This custom record should contain fields for the Vendor Bill ID, Purchase Order ID, and any other relevant information from the Purchase Order line. 6. Use the
record.save
method to save each new custom record. 7. On the Vendor Bill record, create a sublist field that sources from the custom record. This sublist will list all related Purchase Order expense lines. Here's a pseudo-code example:
Copy code
javascript
var vendorBill = record.load({
    type: record.Type.VENDOR_BILL,
    id: vendorBillId
});

var itemCount = vendorBill.getLineCount({
    sublistId: 'item'
});

for (var i = 0; i < itemCount; i++) {
    var purchaseOrderId = vendorBill.getSublistValue({
        sublistId: 'item',
        fieldId: 'orderdoc',
        line: i
    });

    var purchaseOrderLine = vendorBill.getSublistValue({
        sublistId: 'item',
        fieldId: 'orderline',
        line: i
    });

    var customRecord = record.create({
        type: 'customrecord_my_custom_record'
    });

    customRecord.setValue({
        fieldId: 'custrecord_vendor_bill_id',
        value: vendorBillId
    });

    customRecord.setValue({
        fieldId: 'custrecord_purchase_order_id',
        value: purchaseOrderId
    });

    customRecord.setValue({
        fieldId: 'custrecord_purchase_order_line',
        value: purchaseOrderLine
    });

    customRecord.save();
}
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.843761921
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.822267413
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.821908057
Please provide your feedback on this answer.