Unable to get value from Item based on Price Level and Primary currency in Netsuite?

Hi All,

Some times we need price based on Currency and Price Level from customer record.On Customer Record , there are 2 field one is Price level and another field is currency field(required/mandatory field).

Don't forget to download app .

On Item Record there are option to define Price based on currency and price level, Some times we require to get price based on this matrix.

Step 1:
As you need it for all items, and using search inside loop is very bad idea, it is always advisable to get all items in an array .
var i=1;
var itemArray = [];
for(i; i <= lineCount; i++)
{
        var item = nlapiGetLineItemValue('item','item', i);
         itemArray.push(item);
 }





Step 2:

There are 2 way to this:
1. Either make a saved search : Make a saved search and add column where select Unit Price from Pricing Fields... . This will give you Unit price for all items.

pricelevel in netsuite
how to get price based on currency and price level


2. Add above logic inside script only , you can find field's internal id using formula text filter and then select field and submit, you can see id in the box.

Step 3:

You have to pass filter to get line which is only for that item , price level and currency like below:

                  var filters = [];           
                    filters.push(new nlobjSearchFilter('internalid', null, 'anyof', itemArray));
                    if(pricelevel)
                    {
                        filters.push(new nlobjSearchFilter('pricelevel', 'pricing', 'anyof', pricelevel));
                    }
                    if(currency)
                    {
                        filters.push(new nlobjSearchFilter('currency', 'pricing', 'anyof', currency));
                    }
                    var results = nlapiSearchRecord(null, 'customsearch_mysearchid', filters, null);



Step 4: Push all prices into Hashmap to make 1:1 relationship . You can create Hash Map as {} in javascript.
I am also checking that if price level is not defined on customer record then use base price as shown in image above.
                  var ItemValueMapping = {};
                    var itemPushed = [];
                    if(results)
                    {
                        var j=0;
                        var length = results.length;
                        for(j; j < length; j++)
                        {
                            var columns = results[j].getAllColumns();
                            var unitPrice = results[j].getValue(columns[0]);
                            var basePrice = results[j].getValue(columns[1]);                           
                            var itemId = results[j].getId();   
                            if(itemPushed.indexOf(itemId) == -1)
                            {
                                itemPushed.push(itemId);
                                if(pricelevel)
                                {
                                    ItemValueMapping[itemId] = unitPrice;
                                }
                                else
                                {
                                    ItemValueMapping[itemId] = basePrice;
                                }
                            }
                        }
                    }

Step 5:
Now use loop again, go to all item one by one, where item matches with hash map , get the value of price and use it.
Never forget to select line in Script then set current line and then commit line as below
                    if(itemPushed.length > 0)
                    {
                        var k=1;
                        for(k; k <= lineCount; k++)
                        {
                            var itemInt = nlapiGetLineItemValue('item','item', k);
                            var newPrice = ItemValueMapping[itemInt];
                            if(newPrice && (newPrice != 'undefined') && (newPrice != undefined))
                            {
                                nlapiSelectLineItem('item', k);
                                nlapiSetCurrentLineItemValue('item', 'custcol_myfield', newPrice);
                                nlapiCommitLineItem('item')
                            }
                        }
                    }




This is before submit User event but you can use same logic as per your need. Please comment if you have any question or alternative way to do this.

Thanks
Abhi

Download Netsuite Guru Android App
Follow Me on Linkedin
Our FB Page

Comments