multiply all the line item rate with item quantity...
# ask-stanley-ai
i
multiply all the line item rate with item quantity and add the total amount in a body field using aftersubmitfunction
c
AI generated answer (using internal Slack threads):
To multiply all the line item rate with item quantity and add the total amount in a body field using aftersubmitfunction, you can use the following SuiteScript code:
Copy code
javascript
function afterSubmit(context) {
    var newRecord = context.newRecord;
    var lineCount = newRecord.getLineCount({sublistId: 'item'});
    var totalAmount = 0;

    for (var i = 0; i < lineCount; i++) {
        var quantity = newRecord.getSublistValue({
            sublistId: 'item',
            fieldId: 'quantity',
            line: i
        });

        var rate = newRecord.getSublistValue({
            sublistId: 'item',
            fieldId: 'rate',
            line: i
        });

        totalAmount += quantity * rate;
    }

    newRecord.setValue({
        fieldId: 'bodyFieldId', // replace with your body field id
        value: totalAmount
    });

    var recordId = newRecord.save({
        enableSourcing: true,
        ignoreMandatoryFields: true
    });
}
This script will run after a record is submitted. It will iterate over each line in the 'item' sublist, multiply the quantity and rate, and add the result to a running total. After all lines have been processed, it will set the total amount to a body field on the record. Please replace
'bodyFieldId'
with the actual ID of the body field where you want to store the total amount. Remember, this script should be deployed as a User Event Script and should be set to execute on the 'After Submit' event. ****** 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.822547078
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.822227538
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.819894433
Please provide your feedback on this answer.