1

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();
cja
  • 9,512
  • 21
  • 75
  • 129

2 Answers2

0

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?

bknights
  • 14,408
  • 2
  • 18
  • 31
  • See first paragraph of question: "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." – cja Nov 24 '21 at 09:00
  • @cja Is log.debug causing the issue? Ideally we include the title in inverted commas (' '). Just comment all the log.debugs and try once. Let me know. – Sayeesh Nov 24 '21 at 09:24
  • @Finnick I added the logging because of the error. My question was specific about the line on which the error occurs. – cja Nov 24 '21 at 09:55
  • So since your code is not calling `getSublistName ` then review my answer. I've added a bit more. – bknights Nov 24 '21 at 17:03
  • @cja did you figure out the issue? – Morris S Apr 14 '22 at 15:06
0

I had this same problem and filed a defect, 690914 and they estimate it should be fixed in the next few weeks.