Sunday, January 13, 2019

Formula on SuiteScript search to retrieve the correct line item

Retrieving items on the item sublist using line number on the nlobjRecord().getLineItemValue method will get a wrong value
or null value because the method recognize the row number of item in the UI.

For example, on your Sales Order record you have 3 items and its line numbers or ids will be 1, 8, 9
if you use getLineItemValue('item','item',8) it will return a null value but if you use getLineItemValue('item','item',2)
it will return "item B".

1 item A <line>1</line>
2 item B <line>8</line>
3 item C <line>9</line>

In order to retrieve the item based on its line number or id , you can use nlapiSearchRecord and a filter it using
"formulanumeric" since "line" is not available as a search field. Below is a sample script that will return the item
description for item with line number 16:


var filters = new Array();
filters[0] = new nlobjSearchFilter( 'tranid', null, 'is', 'SO141848500');
filters[1] = new nlobjSearchFilter( 'mainline', null, 'is', 'F');
filters[2] = new nlobjSearchFilter( 'formulanumeric', null, 'equalto', 16)
filters[2].setFormula('{line}');


var columns = new Array();
columns[0] = new nlobjSearchColumn( 'description', 'item');

var search_results = nlapiSearchRecord('salesorder',null,filters,columns);

var description = search_results[ 0 ].getValue( 'description', 'item');

nlapiLogExecution('DEBUG','DEBUG',description);

 

No comments:

Post a Comment