Hello all, We are currently making sublocations fo...
# suitescript
x
Hello all, We are currently making sublocations for a few of our locations to keep track of inventory on QC Hold. We will have user event scripts running to automatically transfer from Location to QC Hold after the work order close is created. All items are Lot numbered assembly Items. We already have this running in production for Location A to QC hold A. I recently added QC Hold B to Location B but when I try to do the inventory transfer I get this: "You cannot create an inventory detail for this item." stackTrace: [ "Error\n at RecordInvoker.getCurrentSublistSubrecord This is odd because I have set up both the locations A/B and the QC Hold A/B exactly the same. I can even transfer from Location B to QC Hold A using the same script. The item is for sure lot number assembly Item. I can make the inventory transfer From Location B to QC Hold B perfectly fine through the UI. Any ideas what's going on? Snippet below for testing purposes I have it running on edit of Work Order Close
Copy code
var currentRecord = context.newRecord;
  var stCreatedFrom = currentRecord.getValue({
      fieldId: "createdfrom"
  });
  var objRecord = record.load({
      type: record.Type.WORK_ORDER,
      id: stCreatedFrom
  });
  var customForm = objRecord.getValue({
      fieldId: "customform"
  });
  var qcHold = objRecord.getValue({
      fieldId: "custbody_qc_hold"
  });

  var endDate = objRecord.getValue({
      fieldId: "enddate"
  });

  var stItem = objRecord.getValue({
      fieldId: "assemblyitem"
  });

  var recTransferOrder = record.create({
      type: record.Type.INVENTORY_TRANSFER,
      isDynamic: true
  });
  recTransferOrder.setValue({
      fieldId: 'trandate',
      value: endDate
  });
  recTransferOrder.setValue({
      fieldId: 'location',
      value: LOCATION.LOC_B
  });
  recTransferOrder.setValue({
      fieldId: 'transferlocation',
      value: LOCATION.SUB_B
  });

  recTransferOrder.setValue({
      fieldId: 'custbody_related_wo',
      value: stCreatedFrom
  });

  recTransferOrder.selectNewLine({
      sublistId: 'inventory'
  });
  recTransferOrder.setCurrentSublistValue({
      sublistId: 'inventory',
      fieldId: 'item',
      value: stItem

  });
  recTransferOrder.setCurrentSublistValue({
      sublistId: 'inventory',
      fieldId: 'adjustqtyby',
      value: quantity
  });

  ///inventory number LookUp
  var stInvNum = '';
  if (stItem) {
      log.debug({
          title: 'Lookup inventory detail Look Up',
          details: 'Started'
      });
      var filters = [];
      var columns = [];

      filters[0] = search.createFilter({
          name: 'internalid',
          operator: <http://search.Operator.IS|search.Operator.IS>,
          values: stItem
      });
      filters[1] = search.createFilter({
          name: 'quantityonhand',
          join: 'inventorynumber',
          operator: search.Operator.GREATERTHAN,
          values: 0
      });

      columns[0] = search.createColumn({
          name: 'internalid',
          join: 'inventorynumber'
      });

      var Search = search.create({
          type: search.Type.ITEM,
          filters: filters,
          columns: columns
      });
      var ResultsArray = Search.run().getRange({
          start: 0,
          end: 10
      });
      if (ResultsArray.length > 0) {
          stInvNum = ResultsArray[0].getValue({
              name: 'internalid',
              join: 'inventorynumber'
          });

      }
      log.debug({
          title: 'Inventory Detail ID',
          details: stInvNum
      });
  }
  log.debug({
      title: 'DEBUG BEFORE SUB REC',
      details: recTransferOrder
  });
  log.debug({
      title: 'DEBUG recTransferOrder - inventory',
      details: JSON.parse(JSON.stringify(recTransferOrder)).sublists.inventory
  });
  ////end inventory number lookup
  var inventoryDetailSubrecord = recTransferOrder.getCurrentSublistSubrecord({
      sublistId: 'inventory',
      fieldId: 'inventorydetail'
  });
  // Add a line to the subrecord's inventory assignment sublist.
  inventoryDetailSubrecord.selectNewLine({
      sublistId: 'inventoryassignment'
  });

  inventoryDetailSubrecord.setCurrentSublistValue({
      sublistId: 'inventoryassignment',
      fieldId: 'issueinventorynumber',
      value: stInvNum
  });

  inventoryDetailSubrecord.setCurrentSublistValue({
      sublistId: 'inventoryassignment',
      fieldId: 'quantity',
      value: quantity
  });

  // Save the line in the subrecord's sublist.
  inventoryDetailSubrecord.commitLine({
      sublistId: 'inventoryassignment'
  });


  log.debug({
      title: "Subrecord",
      details: JSON.stringify(inventoryDetailSubrecord)
  });

  recTransferOrder.commitLine({
      sublistId: 'inventory'
  });


  var invTransId = recTransferOrder.save({
      enableSourcing: true,
      ignoreMandatoryFields: true
  });
b
if the item does actually have inventory details, then its likely you messed up a field that needs to be set before inventory details
those would be things like subsidiary, location, and transferlocation
so make sure you actually set those correctly
x
I believe I'm setting in the correct order, I set it in the same order that I would in the UI. Date, From location, to location, item, qty, then inventory detail. the same exact code works when I do location B to QC Hold A. That's what is really throwing me off.
b
the guess is that your variables dont contain the values you expect
check the field's value after setting it to make sure its correct
x
ok yeah it wasn't setting anything for the qc hold b. Hard coded the internal id and that worked. I realized the object I declared outside of the define function that holds all the location ids is acting very unexpected. It might be conflicting with a custom module. welp luckily that is an easy fix. thank you! sometimes you just need someone to point out the obvious 😅