Hi all, I'm a beginner with suitescript - I have a...
# suitescript
l
Hi all, I'm a beginner with suitescript - I have a script to create an inventory adjustment in SS2.0 it works when I call this function via client script, ie - it works on pageInit event but when I call the same function in a RESTlet it fails with "Items you have requested in the record have been deleted since you retrieved the form", any ideas/suggestions?
n
would be great if you could present the code
l
Sure thing, please ignore the types (I'm using typescript). I wrapped the code bellow in a function and I'm calling with the exact same values in a client script and on a restlet:
Copy code
const setRecordValue = (fieldId : Record, value: FieldValue) => {
  record.setValue({fieldId: fieldId, value: value});
}
  const inventoryAdjustmentRec: Record = create({
    type: Type.INVENTORY_ADJUSTMENT,
    isDynamic: false,
  });

  setRecordValue(inventoryAdjustmentRec, 'custom_form', inventoryAdjustment.custom_form_id);
  setRecordValue(inventoryAdjustmentRec, 'tran_date', inventoryAdjustment.transaction_date);
  setRecordValue(inventoryAdjustmentRec, 'subsidiary', inventoryAdjustment.subsidiary_id);
  setRecordValue(inventoryAdjustmentRec, 'account', inventoryAdjustment.account_id);
  setRecordValue(inventoryAdjustmentRec, 'memo', inventoryAdjustment.memo);

  inventoryAdjustment.inventory_list.forEach(function (inventoryListItem: InventoryListItem, index: number) {
    inventoryAdjustmentRec.setSublistValue({
      sublistId: 'inventory',
      fieldId: 'item',
      line: index,
      value: inventoryListItem.item_id
    });

    inventoryAdjustmentRec.setSublistValue({
      sublistId: 'inventory',
      fieldId: 'adjustqtyby',
      line: index,
      value: inventoryListItem.adjust_qty_by
    });

    inventoryAdjustmentRec.setSublistValue({
      sublistId: 'inventory',
      fieldId: 'location',
      line: index,
      value: inventoryListItem.location_id
    });

    inventoryAdjustmentRec.setSublistValue({
      sublistId: 'inventory',
      fieldId: 'unit_cost',
      line: index,
      value: inventoryListItem.unit_cost
    });

    let inventoryDetail : Record = inventoryAdjustmentRec.getSublistSubrecord({
      sublistId: 'inventory',
      fieldId: 'inventorydetail',
      line: index
    });

    inventoryDetail.setSublistValue({
      sublistId: 'inventoryassignment',
      fieldId: 'issueinventorynumber',
      line: index,
      value: '1'
    });

    inventoryDetail.setSublistValue({
      sublistId: 'inventoryassignment',
      fieldId: 'quantity',
      line: index,
      value: inventoryListItem.adjust_qty_by
    });
  });

  inventoryAdjustmentRec.save({
    enableSourcing: true,
    ignoreMandatoryFields: false,
  });
n
it seems like this error is caused by invalid field values. maybe use
log.debug
to check the values
l
right, I will do that. Thanks
n
no worries mate