最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - add an item to a sales order in Netsuite suitescript - Stack Overflow

programmeradmin2浏览0评论

I'm trying to figure out the code behind looking at a new Sales Order that has an item called "Repair" and add a second item called "Repair Cost" before User submit. I'm a bit lost and I wele any help that can be given. I would like this script to be in Javascript and I will attach it to the Sales Order form in Netsuite to run.

I'm trying to figure out the code behind looking at a new Sales Order that has an item called "Repair" and add a second item called "Repair Cost" before User submit. I'm a bit lost and I wele any help that can be given. I would like this script to be in Javascript and I will attach it to the Sales Order form in Netsuite to run.

Share Improve this question edited Mar 11, 2013 at 20:27 Martijn Pieters 1.1m321 gold badges4.2k silver badges3.4k bronze badges asked Mar 11, 2013 at 20:11 RandomlordRandomlord 511 gold badge1 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Here is one sample solution:

We will still assume that the items internal ids are Repair = 100 and Repair Cost = 200

function recalc(type)
{
    if(type == 'item')
    {
        var itemId = nlapiGetCurrentLineItemValue('item', 'item'); //Get the Item ID
        if(itemId == 100) //Repair Cost
        {
                //Insert item
                nlapiSelectNewLineItem('item');
                nlapiSetCurrentLineItemValue('item', 'item', 200); //Repair Cost
                nlapiSetCurrentLineItemValue('item', 'quantity', 1);
                nlapiSetCurrentLineItemValue('item', 'amount', '0.00');
                nlapiCommitLineItem('item');
        }
    }
    return true;
}

Deploy this as client-side code and make sure that the function is Recalc.

To learn more about client side script: https://system.na1suite./help/helpcenter/en_US/Output/Help/SuiteFlex/SuiteScript/SSScriptTypes_ClientScripts.html#1016773

First thing you need to do is to get the internal id of the item "Repair" and "Repair Cost".

In this example, let's assumed that the internal id of Repair = 100 and Repair Cost = 200

Here is th code:

function afterSubmit(type)
{
    if(type == 'create' || type == 'edit')
    {
        var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId()); //Load the record

        //Loop to all sublist item
        var count = record.getLineItemCount('item');
        for(var i = 1; i <= count; i++)
        {
            var item = record.getLineItemValue('item', 'item', i); //This will return the internal id of the item
            if(item == 100) //Item is equal to 100; insert one item
            {
                record.insertLineItem('item', i);
                record.setLineItemValue('item', 'item', i, 200); //Repair Cost internal id
                record.setLineItemValue('item', 'quantity', i, 1); //You should put some quantity; depending on your account setup all required fields should be set here.
            }
        }

        //Submit the changes
        nlapiSubmitRecord(record, true);
    }
}

To understand the suitescript API and the fields exposed to sales order check on this Netsuite helpguide:

https://systemsuite./help/helpcenter/en_US/RecordsBrowser/2012_2/Records/salesorder.html

发布评论

评论列表(0)

  1. 暂无评论