Search code examples
javascriptnetsuitesuitescript

SuiteScript 1.0 nlapiGetLineItemCount


I'm trying to use the nlapiGetLineItemCount('purchaseorder');command to get the number of lines of a Purchase Order. But it just return '-1' .

Is there something wrong with my code?

Thank you!

EDIT: I've also tried nlapiGetLineItemCount('item'); and it's have the same behavior if there is something inexistent. Like this: nlapiGetLineItemCount('trying_lines');

EDIT 2 : I'm trying to use it directly on CONSOLE.


Solution

  • If you tried in browser console you should be in "Edit Mode" (hit the record edit button or add &e=T to record url).

    nlapiGetLineItemCount('item');
    

    ClientScript 2.0

    require(['N/currentRecord'], function (currentRecord) {
          console.log('getLineCount', currentRecord.get().getLineCount({sublistId: 'item'})
    });
    

    UserEvent 2.0 (in before load function)

    function beforeLoad(context){ 
         log.debug('getLineCount', context.newRecord.getLineCount({sublistId: 'item'}))
    }