5

Within my scheduled script I am looping through the items on a transformed Sales Order to Item fulfillment and trying to set the inventory detail as I am looping through the items. The Inventory detail looks to set without any error or issue but when I try to save I get the following error:

Please configure the inventory detail in line 2 of the item list.

Line two is the only item that requires inventory detail in my test. Here is the code:

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

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

for (var i = 0; i < lineCount; i++) {
          itemFulfillment.selectLine({
            sublistId: 'item',
            line: i
          });

          var remainingQty = itemFulfillment.getCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'quantityremaining'
          });

          itemFulfillment.setCurrentSublistValue({
                  sublistId: 'item',
                  fieldId: 'quantity',
                  value: remainingQty
                });

          var inventoryDetail = itemFulfillment.getCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'inventorydetailreq'
          });

          var binItem = itemFulfillment.getCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'binitem'
          });

          if (inventoryDetail === 'T' && binItem === 'T') {

            var inventoryDetailRecord = itemFulfillment.getCurrentSublistSubrecord({
              sublistId: 'item',
              fieldId: 'inventorydetail'
            });                  

            inventoryDetailRecord.selectNewLine({
              sublistId: 'inventoryassignment'
            });


            inventoryDetailRecord.setCurrentSublistValue({
              sublistId: 'inventoryassignment',
              fieldId: 'issueinventorynumber',
              value: 10154 // I know this is the serial number record internal ID for my test
            });

            inventoryDetailRecord.setCurrentSublistValue({
              sublistId: 'inventoryassignment',
              fieldId: 'quantity',
              value: 1 //Again I know this so hard coded for testing
            });

            inventoryDetailRecord.commitLine({
              sublistId: 'inventoryassignment'
            });
          }
        }

        var ifRecordId = itemFulfillment.save();

After committing the Inventory detail if I then check the inventorydetail sub record I can see that the line is there corresponding to line 2 and the correct item. Not sure why when I save it says line 2 needs inventory!

{"type":"inventorydetail","isDynamic":true,"fields":{"itemdescription":"160W PREMIUM GRADE","nlloc":"0","nlsub":"1","trandate":"4/20/2017","_eml_nkey_":"0","type":"inventorydetail","subrecord_parent_tran_type":"ItemShip","nsapiCT":"1492728327986","sys_id":"-19281976277926580","nluser":"-4","nldept":"0","subrecord_transform_from_parent_id":"305887","subrecord_transform_from_parent_tran_type":"SalesOrd","tolocationusesbins":"F","item":"3312","quantity":"1.0","sys_parentid":"19281975969964536","templatestored":"F","entryformquerystring":"orderline=2&unit=&item=3312&quantity=1&subrecord_transform_from_parent_id=305887&trandate=4/20/2017&location=25&uitype=LOH_STRICT_VALIDATION&subrecord_transform_from_parent_tran_type=salesord&subrecord_parent_tran_type=itemship","nlrole":"3","uitype":"LOH_STRICT_VALIDATION","baserecordtype":"inventorydetail","baseunitquantity":"1.0","totalquantity":"1","orderline":"2","haslines":"T","tolocation":"-1","customform":"-10820","location":"25"},"sublists":{"inventoryassignment":{"currentline":{"binnumber":"","binnumber_display":"","existinginventorynumber":"","expirationdate":"","internalid":"-1","inventorydetail":"-1","issueinventorynumber":"","lotquantityavailable":"","quantity":"1","quantityavailable":"","receiptinventorynumber":"","sys_id":"-19281976361182898","sys_parentid":"-19281976277926580","tobinnumber":"","tobinnumber_display":"","#":"2"},"line 1":{"binnumber":"25","binnumber_display":"","existinginventorynumber":"10154","expirationdate":"","internalid":"10154.0","inventorydetail":"-1","issueinventorynumber":"10154","lotquantityavailable":"","quantity":"1.0","quantityavailable":"","receiptinventorynumber":"1793064_3312_NA","sys_id":"-19281976302211623","sys_parentid":"-19281976277926580","tobinnumber":"","tobinnumber_display":""}}}}

I have tried every combination I can think of and followed the suite answer docs to a tee. Have tried setting every value in the Netsuite Records Browser under Item Details / Assignment and still get this error. An help/insight is greatly appreciated.

Superdooperhero
  • 7,584
  • 19
  • 83
  • 138
Ryan
  • 81
  • 1
  • 2
  • 7

5 Answers5

6

I'm DJ. I work as a software developer for NetSuite, on the SuiteScript record service platform team, and I was just looking at this very problem.

The item sublist on the fulfillment record is what we call a "list machine" (as opposed to an "edit machine"). The former are fixed-entry lists where you can edit values but not add or remove lines, whereas "edit machines" are ones where you can also add and remove lines. On the fulfillment record, the list of items is of the non-line-editable variety.

The inventorydetail subrecord on each line of the edit machine (on the item fulfillment record) will only work when you manipulate the subrecord in a mode where isDynamic is false, because the item machine is a list machine and is not compatible with dynamic subrecords. Unfortunately, there is no way to specify the isDynamic attribute of a subrecord, as that attribute currently is inherited from the parent record.

However, you can trick it into doing the right thing! Hence, Ryan's second solution. This solution works around all the limitations as follows:

  1. When transforming the sales order to a fulfillment record, omitting isDynamic causes the fulfillment record to be created as a DeferredDynamic ('standard' mode) record.

  2. When obtaining the inventorydetail subrecord, it will inherit the isDynamic property from the parent record, which means it will be created as a DeferredDynamicSubrecord rather than a DynamicSubRecord. That makes it compatible with the item list machine, and thus the solution works.

I'm working with the product team to see if there's a way to have SuiteScript V2 automatically create each subrecord in the most appropriate mode for its environment (or at least a mode that will work). Or we could provide a way to specify the isDynamic parameter for the subrecord when creating/obtaining it from a record or from a subrecord.

djenning90
  • 197
  • 1
  • 9
3

Ok so bknights did get me thinking. I switched the transform to standard mode:

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

Removed isDynamic: true and worked with the transform record in standard mode. I then only needed to update the current lines inventory detail using the standard API:

        var inventoryDetailRecord = itemFulfillment.getSublistSubrecord({
          sublistId: 'item',
          fieldId: 'inventorydetail',
          line: i
        });

        inventoryDetailRecord.setSublistValue({
          sublistId: 'inventoryassignment',
          fieldId: 'issueinventorynumber',
          value: serialId,
          line: 0
        });

I only needed to set issueinventorynumber that was it and then save the Item Fulfillment record. Definitely confused me as the documentation available on sublists and subrecords for SuiteScript 2 show this being done in dynamic mode and really only show how to create a new inventory number not update and issue one.

Ryan
  • 81
  • 1
  • 2
  • 7
0

It looks like you are trying to do this client side (e.g. with getCurrentSublistSubrecord)

You can't.

What I do is put the necessary info into custom fields and then do this server side either in a User Event script or in a Scheduled script.

As a plus the code is simpler (similar to your sample but for bin assignment):

var invDetail = rec.getSublistSubrecord({
    sublistId: targetList,
    fieldId: 'inventorydetail', 
    line:idx
});
invDetail.setSublistValue({sublistId:'inventoryassignment', fieldId:'binnumber', line:0, value:bintId});
invDetail.setSublistValue({sublistId:'inventoryassignment', fieldId:'quantity', line:0, value:getV(qtyField)});
Superdooperhero
  • 7,584
  • 19
  • 83
  • 138
bknights
  • 14,408
  • 2
  • 18
  • 31
0

Had the same issue with inventorydetail in Dynamic mode. For some reason it was impossible to get number of lines with getLineCount({ sublistId: 'item' })
In my case, I've used while true loop and caught error on selecting each line, best (and most likely only) solution for you is standard mode instead of dynamic.

Ivan
  • 35
  • 2
  • 7
-3

I think you need to read the small print on the documentation about the dynamic mode. When you create a record that is brand new, you need to do the following:

  1. Insert new line
  2. Select new line
  3. Commit new line

I think your code is missing the insert function. I ran into the same situation as you do, and I finally resolved the problem by running the insert new line and select new line commands.

Jason Roman
  • 8,146
  • 10
  • 35
  • 40