title: How to set inventory details when creating vendor bill with SuiteScript?
body: <p>I am attempting to create a vendor bill in SuiteScript which will be generated from  an inbound shipment. It will also retrieve the item receipt's inventory number in order to set inventory details. However, I can't figure out how to set it within SuiteScript since I see no fields when debugging that allow me to set a value for this (currently testing and hoping to explicitly set before moving forward). An example of my code is below:</p>
  
  <pre><code>define(['N/record','N/redirect','N/search'],
  function(record, redirect, search) {
  
  /**
   * Definition of the Suitelet script trigger point.
   *
   * @param {Object} context
   * @param {ServerRequest} context.request - Encapsulation of the incoming request
   * @param {ServerResponse} context.response - Encapsulation of the Suitelet response
   * @Since 2015.2
   */
  function onRequest(context) {
  
      var request = context.request;
      var response = context.response;
  
      var id = context.request.parameters.custom_id;
      if (!id) {
          context.response.write('The parameter "custom_id" is required');
          return;
      }
      else {
          alert('ID is ' + id);
      }
  
      var loadedRecord = record.load({
          type: record.Type.INBOUND_SHIPMENT,
          id: id
      });
  
      alert('Generating vendor bill');
  
      var shipmentBaseCurrency = loadedRecord.getValue('shipmentbasecurrency');
  
      var vendorBill = record.create({
          type: record.Type.VENDOR_BILL,
          isDynamic: true
      });
  
      // retrieve item receipt for inventory details
      var itemReceiptSearchResults = search.create({
          type: "itemreceipt",
          filters:
          [
             ["type","anyof","ItemRcpt"]
             // needs to be linked to shipment
          ],
          columns:
          [
             search.createColumn({name: "mainline", label: "*"}),
             search.createColumn({
                name: "trandate",
                sort: search.Sort.ASC,
                label: "Date"
             }),
             search.createColumn({name: "asofdate", label: "As-Of Date"}),
             search.createColumn({name: "postingperiod", label: "Period"}),
             search.createColumn({name: "taxperiod", label: "Tax Period"}),
             search.createColumn({name: "type", label: "Type"}),
             search.createColumn({name: "tranid", label: "Document Number"}),
             search.createColumn({name: "entity", label: "Name"}),
             search.createColumn({name: "account", label: "Account"}),
             search.createColumn({name: "memo", label: "Memo"}),
             search.createColumn({name: "amount", label: "Amount"}),
  
             search.createColumn({
                name: "inventorynumber",
                join: "inventoryDetail"
          })
          ]
       });
  
      var itemRecIdObj = itemReceiptSearchResults.run().getRange({start:0, end:1});
  
      var itemRecLines = [];
  
      if (itemRecIdObj.length &gt; 0) {
          // loop through items
          var lines = loadedRecord.getLineCount({sublistId: 'items'});
          log.debug("item receipt lines: " + lines);
  
          for (var i = 0; i &lt; lines; i++) {
              var item = loadedRecord.getSublistValue({
                  sublistId: "items",
                  fieldId: "item",
                  line: i
              });
  
              var inventoryDetail = loadedRecord.getSublistValue({
                  sublistId: "items",
                  fieldId: "inventorynumber",
                  line: i
              });
  
              var itemRecValues = {
                  inventoryDetail: inventoryDetail,
                  item: item
              };
  
              itemRecLines.push(itemRecValues);
          }
      }
  
      vendorBill.setValue('currency', shipmentBaseCurrency);
  
      var receivingLocation = '';
  
      var lines = loadedRecord.getLineCount({sublistId: 'items'});
      log.debug("tran. lines: " + lines);
  
      var total;
  
      for (var i = 0; i &lt; lines; i++) {
  
          var quantity = (parseFloat(loadedRecord.getSublistValue({
              sublistId: "items",
              fieldId: "quantityreceived",
              line: i
          })) || 0);
  
          var purchaseOrder = loadedRecord.getSublistValue({
              sublistId: "items",
              fieldId: "purchaseorder",
              line: i
          });
  
          var item = loadedRecord.getSublistValue({
              sublistId: "items",
              fieldId: "itemid",
              line: i
          });
  
          var description = loadedRecord.getSublistValue({
              sublistId: "items",
              fieldId: "shipmentitemdescription",
              line: i
          });
  
          var recLoc = loadedRecord.getSublistValue({
              sublistId: "items",
              fieldId: "receivinglocation",
              line: i
          });
  
          receivingLocation = recLoc;
  
          var totalUnitCost = loadedRecord.getSublistValue({
              sublistId: "items",
              fieldId: "totalunitcost",
              line: i
          });
  
          var amount = loadedRecord.getSublistValue({
              sublistId: "items",
              fieldId: "shipmentitemamount",
              line: i
          });
  
          log.debug("item quantity: " + quantity);
  
          vendorBill = addVendorBillLine(vendorBill, item, quantity, receivingLocation, itemRecLines);
  
      } // for (var i = 0; i &lt; lines; i++)
  
      var vbPostPeriodValStr = String(getPostingPeriod());
      try {
          vendorBill.setText('postingperiod', vbPostPeriodValStr);
      }
      catch(e) {
          log.error('Issue setting posting period for vendor bill', e.message);
      }
  
      vendorBill.setValue('location', receivingLocation);
  
      try {
          var vendorBillId = vendorBill.save(); 
          log.debug('*******Vendor Bill Saved*******', 'Vendor bill successfully saved: ' + vendorBillId);
          redirect.toRecord({
              type: record.Type.VENDOR_BILL, 
              id: vendorBillId 
          });
      }
      catch(e) {
          log.debug('Error saving vendor bill', e.message);
          context.response.write('Error: ' + e.message);
      }
  }
  
  function addVendorBillLine(vendorBill, item, quantity, location, itemRecLines) {
      try {
          var lineNum = vendorBill.selectNewLine({
              sublistId: 'item'
          });
  
          vendorBill.setCurrentSublistValue({
              sublistId: "item",
              fieldId: "item",
              value: item
          });
  
          vendorBill.setCurrentSublistValue({
              sublistId: "item",
              fieldId: "quantity",
              value: quantity
          });
  
          vendorBill.setCurrentSublistValue({
              sublistId: "item",
              fieldId: "location",
              value: location
          });
  
          vendorBill.setCurrentSublistValue({
              sublistId: "item",
              fieldId: "itemtype",
              value: 'NonInvtPart'
          });
  
          // vendorBill.setCurrentSublistValue({
          //     sublistId: "item",
          //     fieldId: "inventorydetailavail",
          //     value: 'F'
          // });
  
          // vendorBill.setCurrentSublistValue({
          //     sublistId: "item",
          //     fieldId: "inventorydetailreq",
          //     value: 'F'
          // });
  
          var itemRecObjInd = itemRecLines.map(function (x) { return x.item; }).indexOf(item);
          var itemRecObj = itemRecLines[itemRecObjInd];
          var inventoryDetail = itemRecObj.inventoryDetail;
          var irItem = itemRecObj.item;
  
          var inventoryDetailRecord = vendorBill.getSublistSubrecord({
              sublistId: 'item',
              fieldId: 'inventorydetail',
              line: lineNum
          });
  
          var hasSubrecord = vendorBill.hasCurrentSublistSubrecord({
              sublistId: 'item',
              fieldId: 'inventorydetail'
          });
  
          if(hasSubrecord){
          var inventoryDetailRecord = vendorBill.getCurrentSublistSubrecord({
              sublistId: 'item',
              fieldId: 'inventorydetail'
          });
  
          inventoryDetailRecord.setSublistValue({
              sublistId: 'inventoryassignment',
              fieldId: 'issueinventorynumber',
              value: '4344111'
          });
          }
  
          vendorBill.commitLine({sublistId:"item"});
  
          log.debug('Committing vendor bill expense line addition','Name: ' + item + ", Quantity: " + quantity);
      }
      catch(e){
          log.debug('Issue committing vendor bill item line addition', e.message);
      }
  
      return vendorBill;
  }
  
  function getPostingPeriod() {
      var monthAbbr = [
          "Jan", "Feb", "Mar", "Apr", "May", "Jun",
          "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
      ];
  
      var d = new Date();
      return monthAbbr[d.getMonth()] + ' ' + d.getFullYear();
  }
  
  return {
      onRequest: onRequest
  };
  
  });
  </code></pre>