Ranganathan Mohanraj
Ranganathan Mohanraj

Reputation: 21

Add New line item in Sales Order Using Suite Script 2.0

I want to add new line item in Sales Order based on the particular Inventory item I select. The new line item should be loaded with the existing item record details in it. For this, I used the below code, but its not working;

function recalc(type)
{
    var itemId = nlapiGetCurrentLineItemValue('item', 'item'); //Get the Item ID
    if(itemId == 16340) //Repair Cost
    {
        alert ("Hi");
        //Insert item
        nlapiSelectNewLineItem('item');
        nlapiSetCurrentLineItemValue('item', 'item', 330); //Repair Cost
        nlapiSetCurrentLineItemValue('item', 'quantity', 1);
        nlapiSetCurrentLineItemValue('item', 'amount', '0.00');
        nlapiCommitLineItem('item');

    }
    return true;
}

Can somebody help to rewrite the code in SS 2.0.

Upvotes: 2

Views: 5452

Answers (1)

Avi
Avi

Reputation: 2069

You can refer SuiteScript 1.0 to SuiteScript 2.0 API Map for NetSuite SuiteScript 1 to 2 API. As for your question, you can use the following

function recalc(type) {
    currentRecord.selectLine({ sublistId: 'item', line: LINE_NO });

    var itemId = currentRecord.getCurrentSublistValue({ sublistId: 'item', fieldId: 'item' }); // Get the Item ID

    if (itemId == 16340) {//Repair Cost
        // Insert item
        currentRecord.selectNewLine({ sublistId: 'item' });

        currentRecord.setCurrentSublistValue({ sublistId: 'item', fieldId: 'item', value: 330 });//Repair Cost
        currentRecord.setCurrentSublistValue({ sublistId: 'item', fieldId: 'quantity', value: 1 });//Repair Cost
        currentRecord.setCurrentSublistValue({ sublistId: 'item', fieldId: 'amount', value: '0.00' });//Repair Cost

        currentRecord.commitLine({ sublistId: 'item' });
    }

    return true;
}

Upvotes: 4

Related Questions