2

I've been wrestling with this for a while now. It may be a bug in NetSuite, but thought I'd consult the SuiteScript ninjas before conceeding to that idea.

Here is the scenario: I have a sales order with a line for a lot numbered inventory item that has the inventory detail pre-filled out with lot information:Order with line with inventory detail Here are the contents of that inventory detail:enter image description here

I'm trying to script the fulfillment for that sales order, but I need to change the inventory detail at the time of fulfillment. This works fine and is permissible in the NetSuite UI, but I can not get a SuiteScript Restlet to do the same. Here is the same code from within the Restlet:

function runFullfillmentTest() {
  var fulfillment = record.transform({
    fromType: 'salesorder',
    fromId: 21424,
    toType: 'itemfulfillment'
  });

  var fulfillmentLineCount = fulfillment.getLineCount({
    sublistId: 'item'
  });

  for (var i = 0; i < fulfillmentLineCount; i++) {
    fulfillment.setSublistValue({
      sublistId: 'item',
      line: i,
      fieldId: 'itemreceive',
      value: false
    });
  }

  // Orderline 3 has the following inventory details pre-set
  // Line |   Lot Number  |   Quantity
  // 0    |   L0001       |   2
  // 1    |   L0002       |   1
  // 2    |   L0003       |   1

  var fulfillmentLineForItem = fulfillment.findSublistLineWithValue({
    sublistId: 'item',
    fieldId: 'orderline',
    value: '3'
  });

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

  fulfillment.setSublistValue({
    sublistId: 'item',
    line: fulfillmentLineForItem,
    fieldId: 'quantity',
    value: '5'
  });

  var inventorydetailForFulfillmentLine = fulfillment.getSublistSubrecord({
    sublistId: 'item',
    fieldId: 'inventorydetail',
    line: fulfillmentLineForItem
  });

  inventorydetailForFulfillmentLine.setValue({
    fieldId: 'quantity',
    value: '5'
  });

  var existingLineCount = inventorydetailForFulfillmentLine.getLineCount({
    sublistId: 'inventoryassignment'
  });

  for (var i = 0; i < existingLineCount; i++) {
    inventorydetailForFulfillmentLine.removeLine({
      sublistId: 'inventoryassignment',
      line: 0
    });
  }

  inventorydetailForFulfillmentLine.insertLine({
    sublistId: 'inventoryassignment',
    line: 0
  });

  inventorydetailForFulfillmentLine.setSublistValue({
    sublistId: 'inventoryassignment',
    line: 0,
    fieldId: 'issueinventorynumber',
    value: '154' // L0003
  });

  // Interestingly enough, if you take out the line below, you'll 
  // get the error: "USER_ERROR : Please enter value(s) for: Serial/Lot Number, Bin, Quantity"
  // So its almost like issueinventorynumber and quantity aren't being seen as
  // being set by NetSuite
  // I think it does see binnumber, but thinks it is invalid because it 
  // believes the issueinventorynumber to be is blank
  inventorydetailForFulfillmentLine.setSublistValue({
    sublistId: 'inventoryassignment',
    line: 0,
    fieldId: 'binnumber',
    value: '111' // W.3.0.0
  });

  inventorydetailForFulfillmentLine.setSublistValue({
    sublistId: 'inventoryassignment',
    line: 0,
    fieldId: 'quantity',
    value: '5'
  });


  // This will throw error:
  // "INVALID_FLD_VALUE : You have entered an Invalid Field Value 111 for the following field: binnumber"
  return fulfillment.save();
}

As shown in the comments, I get the error:"INVALID_FLD_VALUE : You have entered an Invalid Field Value 111 for the following field: binnumber"

In this case 111 is the valid internalid for bin W.3.0.0

Interestingly enough, if remove the line that sets the binnumber to 111 then I get the error:

USER_ERROR : Please enter value(s) for: Serial/Lot Number, Bin, Quantity

Which looks like I am missing the lot and quantity fields, but I just set those? I think it complains about 111 being invalid because it believes the lot number has not been set, and needs that to validate the binnumber.

Any help or other ideas to try are appreciated. I've also tried re-using the existing lines (instead of inserting a new one), but no luck.

Zain Shaikh
  • 6,013
  • 6
  • 41
  • 66
brendonparker
  • 838
  • 8
  • 19

1 Answers1

0

Try saving the inventory detail object, before saving the Item Fulfillment. Remember, you are using "getSublistSubrecord", which loads a record. So after making changes to this, you would need to save the record:

inventorydetailForFulfillmentLine.save();
return fulfillment.save();
Charl
  • 812
  • 1
  • 8
  • 22
  • Hey @Charl long shot but this is the only way I could figure to reach out. Do you know how you resolved this issue back in the day? It's the only post online! "Unable to find a matching line for sublist item with key: [orderLine] and value: [1]" http://quabr.com/47307152/unable-to-find-a-matching-line-for-sublist-item-with-key-orderline-and-value – William W Apr 18 '20 at 01:57
  • @WilliamW It took me a while to realise this was one of my old posts lol. I've undeleted the question. Please go comment on there how you are trying to do this. Are you doing this through a user event script or client script? Comment on my post and I will answer as best I can: https://stackoverflow.com/questions/47307152/unable-to-find-a-matching-line-for-sublist-item-with-key-orderline-and-value – Charl Apr 20 '20 at 22:11