This article is valuable if you are using SuiteScript and you are trying to set defaults on line values with an item fulfillment.
Background
For a recent client implementation, we needed a mechanism to specify the country as part of the item fulfillment at each line level. Because this client is in the media business, they wanted to track the number of user actions that their media produced by country of origin. Naturally, the thought was to create a custom transaction column of type list / record and link it out to the built-in NetSuite country list. Most of the traffic would come from the United States. So we wanted this country to be the default when the item fulfillment record loaded. Yet, with all the typical ways to set defaults on transaction column fields, the conventional way would not work. The strange thing is that if we placed this custom transaction column field on a Sales Order, it acted as expected.
Indeed, it does seem that the item fulfillment behaves different from other transaction types. Thus the need for more inspection, diagnosis and ultimately, resolution.
Solving the Item Fulfillment Default Value Challenge via Client Side SuiteScript
It’s important to remember that the NetSuite UI is HTML. This means we have an opportunity to view the page source and inspect scripts and structure. When doing this, we noticed that our custom field had another related field with a suffix called “_display”. We learned that we had to set the conventional custom field and the related _display one with the values we needed. Below is the client side code pattern we used.
function prd02_clientPageInit() { var COUNTRY_CODE_UNITED_STATES = 230; var COUNTRY_NAME_UNITED_STATES = "United States"; // On an item fulfillment, you need to set both the field and the "_display" extension // otherwise it won't default properly! //confirm that we are in create mode; we expect no record ID if (!nlapiGetRecordId()) for (var i = 1; i <= nlapiGetLineItemCount("item"); i++) { nlapiSetLineItemValue("item", "custcol_prolecto_fulfillment_country", i, COUNTRY_CODE_UNITED_STATES); nlapiSetLineItemValue("item", "custcol_prolecto_fulfillment_country_display", i, COUNTRY_NAME_UNITED_STATES); } }
Enhance Your NetSuite Account
Should you find that you need to extend NetSuite beyond the conventional approaches, or people tell you, “that can’t be done”, let’s have a conversation. We are NetSuite experts and our core competency is innovating on the platform.
The main problem that generates this problem is the behavior of the nlapiSetLineItemValue against the nlapiSetCurrenLineItemValue which is why you have to set the _display field too.
The “Current” version manipulates better the information display on the edited lines, the problem sometimes is, with Item Fulfillments and Item Receipts that you don’t actually edit lines as with everyother transaction.
Carlos,
Thank you! It’s always been peculiar to me that the line based APIs come in two flavors. I hope this helps other developers.
Marty
I used a bit of that code to try and source the values of a custom column into the “PO Rate column. So far it hasn’t thrown any errors but I still can’t get it to work.
This is what I have so far, any advice would be greatly appreciated.
function porrateclientPageInit()
if (!nlapiGetRecordId())
for (var i = 1; i <= nlapiGetLineItemCount("item"); i++) {
var pocost = nlapiGetLineItemValue("item", "custcol_po_cost")
nlapiSetLineItemValue("item", "porate", i, "pocost");
}
}
Are you getting data for pocost?
Here is a code snippet (while in a loop) server side that we use to look up the porate from the Sales Order in a custom column and then drive into into the purchase order:
var poRate = Math.round(salesOrderRec.getLineItemValue('item', 'custcol_prolecto_porate', soLineIdx) * salesOrderRec.getLineItemValue('item', 'rate', soLineIdx) * CONST_PO_RATE_DECIMAL_PLACES) / CONST_PO_RATE_DECIMAL_PLACES;
purchaseOrderRec.setLineItemValue('item', 'rate', poLineIdx, poRate);
purchaseOrderRec.commitLineItem('item');
Marty