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 schadule script
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 a scheduled script, you can use the following approach: 1. Load the record in your scheduled script. 2. Loop through each line item in the sublist. 3. For each line item, get the rate and quantity, multiply them to get the line total. 4. Keep a running total of all line totals. 5. After the loop, set the total amount in a body field. Here is a sample SuiteScript 2.0 code snippet that demonstrates this:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType ScheduledScript
 */
define(['N/record', 'N/search'], function(record, search) {
    function execute(context) {
        var salesOrderId = '123'; // replace with your sales order internal id
        var salesOrderRecord = record.load({
            type: record.Type.SALES_ORDER,
            id: salesOrderId
        });
        var lineCount = salesOrderRecord.getLineCount({ sublistId: 'item' });
        var totalAmount = 0;
        for (var i = 0; i < lineCount; i++) {
            var rate = salesOrderRecord.getSublistValue({ sublistId: 'item', fieldId: 'rate', line: i });
            var quantity = salesOrderRecord.getSublistValue({ sublistId: 'item', fieldId: 'quantity', line: i });
            totalAmount += rate * quantity;
        }
        salesOrderRecord.setValue({ fieldId: 'custbody_total_amount', value: totalAmount });
        var recordId = salesOrderRecord.save();
    }
    return {
        execute: execute
    };
});
In this script, replace
'123'
with the internal id of your sales order, and
'custbody_total_amount'
with the internal id of your custom body field. ****** 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.814586878
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.809051812
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.80883038
Please provide your feedback on this answer.