I am new to scripting and I am trying to create a script in Netsuite that would look at the lines in a sales order and verify if there's a discount item. If there's a discount item, then the script looks at the item just before it, takes the value for field class and updates the discount item's class. 
I am getting Cannot call method "split" of undefined as an error and I am unsure why. 

```
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(["N/record"], function (r){
    function afterSubmitUpdateDiscountClass(context) {

        var currentRecord = context.currentRecord;
        var numLines = currentRecord.getLineCount({
            sublistId: 'item'});

        for(var i=0; i < numLines; i++) {
            var currentItemType = currentRecord.getCurrentSublistValue ({
                sublistID: 'item',
                fieldID: 'itemType',
                line: i});

            if (currentItemType == 'discountitem') {
                var newClass = currentRecord.getCurrentSublistValue ({
                    sublistID : 'item',
                    fieldID: 'class',
                    line: i-1});
                currentRecord.selectLine({
                    sublistID: 'item',
                    line: i })
                currentRecord.setCurrentSublistValue ({
                    sublistID : 'item',
                    fieldID: 'class',
                    value : newClass });

                currentRecord.commitLine({
                    sublistID: 'item' });

            }
        }
    }
    return {
        afterSubmit: afterSubmitUpdateDiscountClass
    }
})

```