How to handle inventory details, getting an error? - netsuite

This is my code:
var invAdjRec = nlapiCreateRecord('inventoryadjustment');
var lotNumber = "lot123456";
invAdjRec.setFieldValue('account', '850');
invAdjRec.selectNewLineItem('inventory');
invAdjRec.setCurrentLineItemValue('inventory', 'item', '2904');
invAdjRec.setCurrentLineItemValue('inventory', 'location', '3');
invAdjRec.setCurrentLineItemValue('inventory', 'adjustqtyby', '10');
var inventoryDetail = invAdjRec.createCurrentLineItemSubrecord('inventory','inventorydetail');
inventoryDetail.selectNewLineItem('inventoryassignment'); inventoryDetail.setCurrentLineItemValue('inventoryassignment', 'issueinventorynumber', lotNumber);
inventoryDetail.setCurrentLineItemValue('inventoryassignment', 'quantity', 10);
inventoryDetail.commitLineItem('inventoryassignment'); inventoryDetail.commit();
invAdjRec.commitLineItem('inventory');
nlapiSubmitRecord(invAdjRec);
This is my error:
Please enter value(s) for: Serial/Lot Number

Looks like, according to that error message, you are just missing: serialnumber.
invAdjRec.setCurrentLineItemValue('inventory','serialnumber',lotNumber);

The issueinventorynumber field is a select field of a inventorynumber record and expects an internal id passed in. If the lot you wish to set exists, you can examine an existing record that uses it to obtain the id. If the Lot Number does not yet exist, you may not be able to create it.

In your script, you use issueinventorynumber field id as the quantity to be adjusted, but this can only be used for negative inventory adjustments. For positive inventory adjustments, you need to use receiptinventorynumber instead

There's another field not listed in the record browser that must be set:
subrecordInvDetail.setCurrentSublistValue({
sublistId: 'inventoryassignment',
fieldId: 'receiptinventorynumber',
value: serialNumber
});

Related

Netsuite casetaskevent value not accepted

I'm taking over an existing setup and trying to update a form by added a new option for the user. I need to have casetaskevent set to a value but when I attempt to process it like this:
timebillRec.setValue ({
fieldId: 'casetaskevent',
value: taskid,
ignoreFieldChange: true
})
I get the error: You have entered an Invalid Field Value 673 for the following field: casetaskevent
I think the person before me set acceptable values for casetaskevent but I can't for the life of me figure out where that's set. Based on docs, this is a standard id I'm targeting for timebill.
Where can I updated the accepted values?

NetSuite Suitescript 2.0 How can I access custom item options records?

I have a problem that I'm trying to solve in a roundabout way since the straightforward way didn't work.
The task: Retrieve the customizable item options off of a purchase order item (using SuiteScript 2.0).
The partial solution: Currently, I extract the itemId off the PO using
po.getCurrentSublistValue({ sublistId: 'item', fieldId: 'item' });
Then I load the item and extract the item options IDs and labels using
var optionIds = item.getValue({ fieldId: 'itemoptions' });
var optionLabels = item.getText({ fieldId: 'itemoptions' });
For item options that aren't List/Record type, (like freeform text personalization), I can then loop through the item options and extract their text off of the PO item using the following code.
for (var j = 0; j < optionIds.length; j++) {
var option = po.getCurrentSublistText({
sublistId: 'item',
fieldId: optionIds[j].toLowerCase()
});
if (option !== null) {
log.debug({title: 'option found', details: optionLabels[j] + ': ' + option});
}
}
The issue: When the item option is a List/Record type, both getCurrentSublistText and getCurrentSublistValuereturn the internal ID of the list selection. For instance, if I have a custom item option for Shirt Color, and it uses the custom list Color, with Red being internal ID 2, then if my PO has an item with red shirt color on it, the option label will be "Shirt Color", but instead of "Red," the option will be 2, the internal ID from the Color list. I have no idea why getCurrentSublistText doesn't work for this use case, but I've accepted it, and I'm looking for a workaround.
My thought was, since the item option is a record in the UI (my field explorer extension says it has recordType:"itemoptioncustomfield"), I could just load it up using the option ID that I have, and if it has fieldtype:"SELECT", I would get the internal ID of the List/Record selection (fieldId: selectrecordtype) then use search.lookupFields to get the actual value of my item option, instead of the internal ID. The only issue is, I can find no way to load (or search on) an item option. The record type does not seem to exist in SuiteScript (I believe in Suite Talk it does though). Is this a possible task? Even if my workaround can't work, is there another better workaround that I'm not seeing?
Thanks in advance, I'm at a loss here.
Edit: Just to add further attempts, I found the Field.getSelectOptions() function today which looked really promising, since it would list all the select options of the item option and their values I would think. I tested it out on some other more basic fields on the order and it worked, however when I tried using getCurrentSublistField on the item option field (just as I used getCurrentSublistValue and getCurrentSublistText, the field returned was null, so looks like that is another dead end.

Displaying all the fields of 'item' sub list of purchase orders in net suite

I'm trying to display all the fields of 'item' sub list of purchase orders.
Currently I am using the following to fetch value of a specific sublist field.
var custcol_landedcost_ir_refno = currentRecord.getSublistValue({
sublistId : 'item',
fieldId : 'custcol_landedcost_ir_refno',
line : i
});
here we have more number of fields to display. How can we print all the fields within the 'item' sub list without specifying each and every field like above?
Thanks in Advance!
You can use getSublistFields to fetch a list of fields within a sublist.
Here is the documentation for it.
eg
var lineItemFieldsList = poRecord.getSublistFields({ sublistId: 'item' });

Unable to find a matching line for sublist item with key: [orderLine] and value: [1]

I am using SuiteTalk to create an item fulfillment from an existing sales order. This works for non-serialized orders, but not for serialized SOs.
I get the following error:
Unable to find a matching line for sublist item with key: [orderLine] and value: [1].
The line numbers do however match, since there is only one line, and this has line number "1". The line item does have a quantity of 3, each item being added to the fulfillment separately with the same line number. Could this be the problem?
My code:
ItemFulfillmentItem ffItem = new ItemFulfillmentItem();
ffItem.item = ifitemlist.item[b].item;
ffItem.itemReceive = true;
ffItem.itemReceiveSpecified = true;
ffItem.itemIsFulfilled = true;
ffItem.itemIsFulfilledSpecified = true;
ffItem.orderLineSpecified = true;
ffItem.orderLine = ifitemlist.item[b].orderLine;
ffItem.quantity = msg.despatchCartons[i].items[a].qtyDespatched;
ffItem.quantitySpecified = true;
ifitems.Add(ffItem);
For the specific fulfillment, the above code runs 3 times. This is because each of the 3 items on this Line has a separate serial number.
Any help would be appreciated. Thanks in advance!
To resolve this, you need to create an Inventory Detail record for each line on the Item Fulfillment record. The Inventory Detail record will contain the serial number and quantity per serial number for the specific line item.
The SuiteScript 2.0 code for this, using a User Event script:
var currentRecord = scriptContext.currentRecord;
var subrecordInvDetail = currentRecord.getSublistSubrecord({
sublistId: 'item',
fieldId: 'inventorydetail',
line: item_line_num
});
Run the following code for each serial number on your current line:
subrecordInvDetail.setSublistValue({
sublistId: 'inventoryassignment',
fieldId: 'issueinventorynumber',
line: serial_num_line,
value: 'Serial_Number'
});
subrecordInvDetail.setSublistValue({
sublistId: 'inventoryassignment',
fieldId: 'quantity',
line: serial_num_line,
value: 'Quantity_Value'
});
subrecordInvDetail.save();
This is the first thing that pops up when I google for the same error, so hopefully this may help someone and save a few hours of their life ! I know it's not strictly an answer to the question asked. In my case I had this same error when trying to create an Item Receipt for a Purchase Order. The issue turned out to be that I was not incrementing the lineOrder parameter for the ItemReceiptItem. Therefore I had multiple lines in the Item Receipt that had the same lineOrder (which matches to that in the original Purchase Order). Would have been more useful if the error message said something along the lines that there were duplicates.

NetSuite - using nlapiCopyRecord function

I am generating an invoice when the original invoice is overdue by a certain time period. I want to know if we can use the nlapiCopyRecord to make a copy of the original invoice but allow us to insert a new line that will replace the old line item? I haven't found any sample to show how this is done.
Thanks.
Edit 1:
var new_inv = nlapiCopyRecord('invoice', internal_id,
{
item : 66,
amount: amount,
description: 'TEST'
});
var copiedId = nlapiSubmitRecord(new_inv);
return copiedId;
Above code fails in my scheduled script. You have entered an invalid default value for this record initialize operation.
I would like to override the line item on the newly copied invoice
Yes that is possible, just like if you copy a record in the UI you can modify the copy. You also need to remember that you need to save the record object after you have copied it.
Why are you doing this? If you are trying to charge a late fee you'd probably be better off by adding an expense line to the original invoice record. If you don't have expenses turned on then you could add an other "Other Charge for Sale"
If your code is running server side then:
var invRec = nlapiLoadRecord('invoice', internal_id);
var chargeIndex = invRec.getLineItemCount('item') + 1;
// don't think you need this for the end position invRec.insertLineItem('item', chargeIndex);
invRec.setLineItemValue('item', 'item', chargeIndex, charge_item_id);
invRec.setLineItemValue('item', 'rate', chargeIndex, amount);
invRec.setLineItemValue('item', 'amount', chargeIndex, amount);
nlapiSubmitRecord(invRec);
OR if you use an expense
var invRec = nlapiLoadRecord('invoice', internal_id);
invRec.insertLineItem('expense', 1);
invRec.setLineItemValue('expense', 'account', 1, penalty_account);
invRec.setLineItemValue('expense', 'amount', 1, amount);
invRec.setLineItemValue('expense', 'memo', 1, 'TEST');
nlapiSubmitRecord(invRec);

Resources