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

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' });

Related

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.

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 SuiteScript 2.0 how to update Sales Order Item which is part of the Item Group

I'm trying to update Term field on Sales Order Item Line in NetSuite.
I can do that fine using ue (user event script) on beforeSubmit event.
That works when I hit Save button when Sales Order is in Edit mode.
Now, the issue:
I am trying to update Sales Order Item field (Term) BEFORE Save button is hit but AFTER Add button is clicked, for components of Item Group.
I have written a function and added to postSourcing(scriptContaxt) event that does the updating but it works only for NON-Inventory Items.
This does not work for Item Groups.
When Item Group is added to the Sales Order, inventory (components) are automatically populated onto the form.
Does anybody know what event is triggered when components of Item Group are added to the Sales Order form?
Thank you
Kris
OK... Further research and explanation:
This is the code for updating a single filed when Non-Inventory Item is added to the Sales Order (adding SKU number to the Sales Order Line):
function postSourcing(scriptContext)
{
setSalesOrderItemTerm(scriptContext.currentRecord);
}
function setSalesOrderItemTerm(salesorder)
{
var itemId = salesorder.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'item'
});
if(!itemId)
return;
var result = search.create({
type: search.Type.ITEM,
columns: ['custitem_abs_item_term'],
filters: [{name: 'internalid',operator: search.Operator.IS,values: itemId},
{name: 'isinactive',operator: search.Operator.IS,values: 'F'}]
}).run().getRange({start: 0, end: 1});
if(result.length > 0)
{
var term = result[0].getValue('custitem_abs_item_term');
salesorder.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_swe_contract_item_term_months',
value: term
});
}
}
This works absolutely fine for a single, Non-Inventory Item.
On the other hand when I try to add Item Group (this is different than KIT) the Term field (id: custcol_swe_contract_item_term_months) is not being updated from its item, the Term field is updated with value on the Item Group.
FYI. Item Group is constructed with Item Group (Group Header called Group), its components (other Item types i.e. Non-Inventory Items) and Empty Items (called End Group -> usually empty)
So when you have an Item Group that has two Non-Inventory Items in it and you try to add that Item Group to Sales Order those two Non-Inventory items will be automatically added to Sales Order (along with Group and End Group row).
I am trying to find out on what event those two Non-Inventory items are added to Sales Order.
I hope this is more clear now.
Thank you
Kris
My answer below, also applies to this
https://stackoverflow.com/a/44013939/5389329 "Creating a SalesOrder within NetSuite with Item Groups"

Netsuite: Manually modify [invoiced] field in Sales Order > Item subtab

Is there any way to manually modify [invoiced] field in Sales Order > Item subtab via SuiteScript?
Currently I am able to update this field via nlapiTransformRecord(sales order to invoice), but in case there are two item fulfillment for same item, I do not want to combine these together instead I want to show two rows in Invoice. I am able to achieve this by using SelectNewLineItem but the problem is the [invoiced] field is not being updated. Please help. Thanks.
As show in below, if I use SelectLineItem it works perfectly. But SelectNewLineItem somehow failed to update the [invoiced] field.
var newrecords = nlapiTransformRecord('salesorder', results[0][9],
'invoice', {
recordmode : 'dynamic'
});
//Temporary hardcoded this to 2 for testing
if (m == 2) {
newrecords.selectNewLineItem('item');
newrecords.setCurrentLineItemValue('item', 'item',
results[m][10]);
newrecords.setCurrentLineItemValue('item', 'quantity',
results[m][4]);
newrecords.setCurrentLineItemValue('item', 'amount',
results[m][5]);
newrecords.commitLineItem('item');
} else {
var lineNum = newrecords.findLineItemValue('item', 'item',
results[m][10]);
newrecords.selectLineItem('item', lineNum);
newrecords.setCurrentLineItemValue('item', 'item',
results[m][10]);
newrecords.setCurrentLineItemValue('item', 'quantity',
results[m][4]);
newrecords.setCurrentLineItemValue('item', 'amount',
results[m][5]);
newrecords.commitLineItem('item');
}
}
nlapiSubmitRecord(newrecords, false, true);}
I don't believe this is possible.
Basically, there are two types of lines on Invoices - those linked to a Sales Order, and standalone lines. Linked lines will reflect back to the Sales Order, and do not change stock on hand (as that is changed by the Fulfillment), while standalone lines have no connection to the Sales Order.
The only (API supported) way to create an Invoice that is linked back to the Sales Order is using nlapiTransformRecord(). If you then manually add lines with record.selectNewLineItem() they cannot be linked back.

How to handle inventory details, getting an error?

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
});

Resources