Set line items in custom sublist

2.5k Views Asked by At

A lot of tutorials or reference on how to deal with netsuite sublist but none of them fits what I needed.

I just need to update/add the custom sublist I created in suitelet through client script. This is my suitelet code

    //this is a custom sublist
    var sublist = form.addSubList('targetlist', 'list', null, 'target_list');
    sublist.addField('industry', 'text', 'Industry');
    sublist.addField('inp_name', 'text', 'Name');

And in client script I just want to add some line items when some field change like

function targetListClient(type, name, lineNum) {
    if(name == 'industry') { 
          nlapiSelectNewLineItem('targetlist');
          nlapiSetCurrentLineItemValue('targetlist', 'industry', 'test');
          nlapiSetCurrentLineItemValue('targetlist', 'inp_name', 'test again');
          nlapiSetCurrentLineItemValue('targetlist', 'jobtitle', 'another test');
          nlapiCommitLineItem('targetlist');
    }

}

I think this should work but I got this error. Uncaught TypeError: Cannot read property 'checkvalid' of undefined

I also try to just set the line item nlapiSetLineItemValue('industry', 1, 'again') instead of selecting the current line item but this also is not working.

Am I implementing the sublist concept incorrect? Can someone guide me on this. Thanks.

4

There are 4 best solutions below

0
On

In function targetListClient, you give a value for field jobtitle, but the sublist creation code only has fields industry and inp_name.

1
On

Does your code also have the form.setScript? You mentioned a client side script. You need to attach the client side script to your suitelet using form.setScript.

0
On

change the "LIST" to "INLINEEDITOR" and it will work 100%

1
On

Try using this:

nlapiSetCurrentLineItemValue('targetlist', 'industry', 'test',false,true);

Explanation: nlapiSetCurrentLineItemValue has firefieldchanged argument which is set to true by default if you don't set it to false fieldChanged script is called repeatedly causing infinte loop .So try setting it to false .This should solve the problem