i want to check if the lot inventory number that i...
# ask-stanley-ai
n
i want to check if the lot inventory number that i added in the current item line ends with 24 then i will commit the current line and i will add a new line with the same item bt a quantity of 2 and it will have rate 0. i want to implement this using suitescript 2.0
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that you can't directly modify the 'quantity committed' via SuiteScript, but you can modify the 'quantity' which indirectly affects the 'quantity committed'. To implement your requirement, you can use SuiteScript 2.0 to check if the lot inventory number ends with '24', commit the current line, and then add a new line with the same item but with a quantity of 2 and a rate of 0. Here is a sample code snippet that might help you:
Copy code
javascript
define(['N/record'], function(record) {
    function checkLotNumberAndAddLine(recordId) {
        var itemRecord = record.load({
            type: record.Type.INVENTORY_ITEM, 
            id: recordId
        });
        
        var numLines = itemRecord.getLineCount({sublistId: 'inventory'});
        
        for (var i = 0; i < numLines; i++) {
            var lotNumber = itemRecord.getSublistValue({
                sublistId: 'inventory',
                fieldId: 'lotnumber',
                line: i
            });
            
            if (lotNumber.endsWith('24')) {
                itemRecord.selectLine({sublistId: 'inventory', line: i});
                itemRecord.commitLine({sublistId: 'inventory'});
                
                itemRecord.selectNewLine({sublistId: 'inventory'});
                itemRecord.setCurrentSublistValue({
                    sublistId: 'inventory',
                    fieldId: 'item',
                    value: itemRecord.getValue({fieldId: 'item'})
                });
                itemRecord.setCurrentSublistValue({
                    sublistId: 'inventory',
                    fieldId: 'quantity',
                    value: 2
                });
                itemRecord.setCurrentSublistValue({
                    sublistId: 'inventory',
                    fieldId: 'rate',
                    value: 0
                });
                itemRecord.commitLine({sublistId: 'inventory'});
            }
        }
        
        itemRecord.save();
    }
    
    return {
        checkLotNumberAndAddLine: checkLotNumberAndAddLine
    };
});
This script loads an inventory item record, iterates over the inventory sublist, checks if the lot number ends with '24', commits the line, and adds a new line with the same item, a quantity of 2, and a rate of 0. ****** 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.852478147
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.840637207
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.839172363
Please provide your feedback on this answer.