This article is relevant if you seek to understand how to program NetSuite’s vendor purchase price list on the item record.
Background
In the article Maintain NetSuite Foreign Currency Item Purchase Price Lists I illustrate how to maintain a NetSuite purchase price list using native and custom structures. One of our clients sought a mechanism to update NetSuite’s native vendor purchase price list using some techniques that required script. The price list can be maintained in different currencies. Since it was not documented well, one our senior consultants brought forth the code pattern. I bring it here to you.
NetSuite SuiteScript 2.0 to Update Vendor Item Price List
Below is the basic and simple SuiteScript 2.0 script to help illustrate the pattern to read and update the vendor item purchase price list. See related image for an example of the vendor item list we are updating.
/** * @NApiVersion 2.x * @NScriptType UserEventScript * @NModuleScope SameAccount */ define(['N/record', 'N/search'], /** * @param {record} record * @param {search} search */ function(record, search) { /** * Function definition to illustrate how to update the currency price list offered by a vendor. */ function beforeLoad(scriptContext) { //for learning, hard code loading the item we are working with var itemRecord = record.load({type: record.Type.INVENTORY_ITEM, id: 501}); //get the item's vendor price sublist var sublistRecord = itemRecord.getSublistSubrecord({ sublistId: 'itemvendor', fieldId: 'itemvendorprice', line: 0 }); //spin through the sublist of prices; arbitrarily update the price to illustrate how var count = sublistRecord.getLineCount({sublistId: 'itemvendorpricelines'}); for ( var i=0; i < count ; i++) { var id = sublistRecord.getSublistValue({sublistId: 'itemvendorpricelines', fieldId: 'id', line: i}); var vendorcurrency = sublistRecord.getSublistValue({sublistId: 'itemvendorpricelines', fieldId: 'vendorcurrency', line: i}); var vendorcurrencytext = sublistRecord.getSublistText({sublistId: 'itemvendorpricelines', fieldId: 'vendorcurrency', line: i}); var vendorprice = sublistRecord.getSublistValue({sublistId: 'itemvendorpricelines', fieldId: 'vendorprice', line: i}); log.debug(id + vendorcurrency + vendorcurrencytext, vendorprice); sublistRecord.setSublistValue({sublistId: 'itemvendorpricelines', fieldId: 'vendorprice', line: i, value: (i+1)*1000}); } //commit the item record. The sublist will update itemRecord.save(); } return { beforeLoad: beforeLoad, }; });
NetSuite Enhancement Support
NetSuite’s platform is designed to be enhanced to meet operational business requirements. If you are looking to be part of a team of professionals that appreciate innovation, technology, and leadership, let’s have a conversation.
Its not working. Did i miss something?
Hi Marty,
One issue with your code is that SS2 does not provide a way to commit subrecord. As per NS help article /app/help/helpcenter.nl?fid=section_4267286323.html for
Record.save()
:The SS1 -> SS2 map entry for
nlobjSubrecord.commit()
says:The solution to this seems to be omitting saving subrecord at all.
Thanks,
Lukasz
Thank you Lukasz for the extra information.
Best. Marty