using client side suite script, please create a sc...
# ask-stanley-ai
m
using client side suite script, please create a script that takes all the line items, and for each inventory type insert a line with a discount item with a percentage of 10% for each item.
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems like you are trying to add a discount line item for each inventory item in a sales order using client-side SuiteScript. Here's a sample script that might help you:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
define(['N/record', 'N/currentRecord'], function(record, currentRecord) {
    function lineInit(scriptContext) {
        var currentRec = scriptContext.currentRecord;
        var sublistName = scriptContext.sublistId;

        if (sublistName === 'item') {
            var itemType = currentRec.getCurrentSublistValue({
                sublistId: 'item',
                fieldId: 'itemtype'
            });

            if (itemType === 'InvtPart') {
                var itemRate = currentRec.getCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'rate'
                });

                var discountRate = itemRate * 0.10; // 10% discount

                currentRec.selectNewLine({
                    sublistId: 'item'
                });

                currentRec.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'item',
                    value: 'DISCOUNT_ITEM_ID' // replace with your discount item internal id
                });

                currentRec.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'rate',
                    value: discountRate
                });

                currentRec.commitLine({
                    sublistId: 'item'
                });
            }
        }
    }

    return {
        lineInit: lineInit
    };
});
This script listens to the
lineInit
event, which is triggered whenever a line item is initialized. It checks if the line item is an inventory item (
InvtPart
). If it is, it calculates a 10% discount based on the item's rate, then adds a new line with the discount item and the calculated discount rate. Please replace
'DISCOUNT_ITEM_ID'
with the internal ID of your discount item. ****** 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.851885676
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.830416501
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.826088488
Please provide your feedback on this answer.