'Why do I get “field.getSublistName is not a function” when setting a sublist value?

I'm trying to transform a sales order to an item fulfillment using a SS 2.0 button event handler. As simple as possible. Not trying to do anything complicated. Surely something that has been done thousands of times before.

I get error "field.getSublistName is not a function" on the line after the todo:

var itemFulfillment = record.transform({
    fromType: record.Type.SALES_ORDER,
    fromId: salesOrderId,
    toType: record.Type.ITEM_FULFILLMENT,
    isDynamic: true
});

var lineCount = itemFulfillment.getLineCount({
    sublistId: 'item'
});

log.debug({
    title: FUNCTION_NAME,
    details: {
        lineCount: lineCount
    }
});

for (var i = 0; i < lineCount; i++) {

    itemFulfillment.selectLine({
        sublistId: 'item',
        line: i
    });

    log.debug({
        title: FUNCTION_NAME,
        details: '1'
    });

    //todo error on next time: field.getSublistName is not a function

    itemFulfillment.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'itemreceive',
        value: true
    });

    log.debug({
        title: FUNCTION_NAME,
        details: '2'
    });

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

log.debug({
    title: FUNCTION_NAME,
    details: '3'
});

const id = itemFulfillment.save();

If I try in non-dynamic mode then I get the same error:

var itemFulfillment = record.transform({
    fromType: record.Type.SALES_ORDER,
    fromId: salesOrderId,
    toType: record.Type.ITEM_FULFILLMENT
});

var lineCount = itemFulfillment.getLineCount({
    sublistId: 'item'
});

log.debug({
    title: FUNCTION_NAME,
    details: {
        lineCount: lineCount
    }
});

for (var i = 0; i < lineCount; i++) {

    log.debug({
        title: FUNCTION_NAME,
        details: '1'
    });

    //todo error on next time: field.getSublistName is not a function

    itemFulfillment.setSublistValue({
        sublistId: 'item',
        line: i,
        fieldId: 'itemreceive',
        value: true
    });

    log.debug({
        title: FUNCTION_NAME,
        details: '2'
    });
}

log.debug({
    title: FUNCTION_NAME,
    details: '3'
});

const id = itemFulfillment.save();


Solution 1:[1]

I've never come across getSublistName. If that's an error being thrown when you set the field value then I'd look for a client script (or a workflow) that runs when you set the field.

From the n/currentRecord module your options for like named functions are:

  • getSublist
  • getSublistField
  • getSublistText
  • getSublistValue

and of course the getCurrentSublistxxx variants.

What are you trying to do?

If there are no other scripts running (although since this also occurs in non-dynamic mode I'd suspect a workflow) then there may be something in NS that is throwing this. It may be that the sales order you are transforming isn't ready for fulfillment. It may also be that itemreceive is already set on the record. Whether to automatically include or exclude line items in a fulfillment is controlled at the account level. What happens when you create the itemfulfillment from the UI?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1