Hello. I am trying to update the line items of an ...
# suitescript
n
Hello. I am trying to update the line items of an already created inventory adjustment record. I want to change the quantity and the lot numbers but it is throwing error: "You still need to reconfigure the inventory detail record after changing the quantity." Any help on this?
b
Probably need to share the code
Your error is saying the quantity on the adjustment line doesnt match the quantity from the inventory detail
n
Oh.. Let me confirm that.
Copy code
var invAdjRecord = nsRecord.load({
   type: 'inventoryadjustment',
   id: context.key
});
var values = JSON.parse(context.value);

for (var itemId in values) {
   if (values.hasOwnProperty(itemId)) {
      log.debug('updateInvAdjust::itemId loop', itemId);
      log.debug('updateInvAdjust::values[itemId]', values[itemId]);

      var lineNumber = invAdjRecord.findSublistLineWithValue({
         sublistId: 'inventory',
         fieldId: 'item',
         value: itemId
      });
      log.debug('lineNumber', lineNumber);
      if (lineNumber > -1) {
         invAdjRecord.setSublistValue({
            sublistId: 'inventory',
            fieldId: 'newquantity',
            line: lineNumber,
            value: values[itemId].quantity
         });
         invAdjRecord.setSublistValue({
            sublistId: 'inventory',
            fieldId: 'unitcost',
            line: lineNumber,
            value: values[itemId].avgCost
         });

         var lotNumRec = invAdjRecord.getSublistSubrecord({
            sublistId: 'inventory',
            fieldId: 'inventorydetail',
            line: lineNumber
         });

         var lotData = values[itemId].inventoryDetails;
         for(var i = 0; i < lotData.length; i++){
            log.debug('lotData[i].expirydate', lotData[i].expirydate);
            var date = nsFormat.parse({value: lotData[i].expirydate, type: 'date'});
            log.debug('date', date);
            lotNumRec.setSublistValue({
               sublistId: 'inventoryassignment',
               fieldId: 'receiptinventorynumber',
               line: i,
               value: lotData[i].lotnumber
            });
            lotNumRec.setSublistValue({
               sublistId: 'inventoryassignment',
               fieldId: 'expirationdate',
               line: i,
               value: date
            });
            lotNumRec.setSublistValue({
               sublistId: 'inventoryassignment',
               fieldId: 'quantity',
               line: i,
               value: lotData[i].quantity
            });
         }
      }
quantities are same.
b
Without seeing the data
My guess is that the new inventory detail line count is smaller than the old inventory detail line count
I dont see logic removing the extra old lines
n
There is no old lines.
The items are same. We just need to update the old items.
Should I delete the already added items?
b
If they have old inventory details. Yes
You dont remove old inventory detail lines
So if there is more existing lines than new lines, you have extra old lines messing up quantity
That said, editing adjustments is the road to negative inventory
Be very clear about why editing an inventory adjustment is your chosen solution
n
Copy code
{
  "quantity": 2,
  "inventoryDetails": [
    {
      "lotnumber": "31-05-2021",
      "expirydate": "31/05/2021",
      "quantity": "2",
      "lineId": "1"
    }
  ],
  "location": "Abu Dhabi",
  "avgCost": "10"
}
This is the data
b
How many inventory detail lines on the matching item
n
Only 1
It's not allowing to adjust quantity either.
b
try setting adjustqtyby instead
it should probably be the new quantity minus the existing quantity on hand
n
I am now getting this error: You still need to reconfigure the inventory detail record after changing the quantity.
b
dunno what to tell you
Copy code
require(["N/record"], function(record) {
  var invAdjRecord = record.load({
    type: "inventoryadjustment",
    id: 'pickYourId'
  });
  invAdjRecord.setSublistValue({
    sublistId: "inventory",
    fieldId: "adjustqtyby",
    line: 0,
    value: 4
  });
  var lotNumRec = invAdjRecord.getSublistSubrecord({
    sublistId: "inventory",
    fieldId: "inventorydetail",
    line: 0
  });
  lotNumRec.setSublistValue({
    sublistId: "inventoryassignment",
    fieldId: "quantity",
    line: 0,
    value: 4
  });
  lotNumRec.setSublistValue({
    sublistId: "inventoryassignment",
    fieldId: "receiptinventorynumber",
    line: 0,
    value: new Date().toISOString()
  });

  invAdjRecord.save();
});
that pretty much edits the first line of an inventory adjustment with an inventory detail for me
you can try it out on your side
n
Resolved the issue.
Dynamic record helped.
The 2nd item had 2 lot numbers. I was only setting 1 based on CSV.
186 Views