简体   繁体   English

在Netsuite suitescript中将商品添加到销售订单

[英]add an item to a sales order in Netsuite suitescript

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 welcome 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. 我希望这个脚本在Javascript中,我会将它附加到Netsuite中的Sales Order表单中运行。

Here is one sample solution: 这是一个示例解决方案:

We will still assume that the items internal ids are Repair = 100 and Repair Cost = 200 我们仍然假设项目内部ID是Repair = 100和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. 将其部署为客户端代码并确保该函数为Recalc。

To learn more about client side script: https://system.na1.netsuite.com/help/helpcenter/en_US/Output/Help/SuiteFlex/SuiteScript/SSScriptTypes_ClientScripts.html#1016773 要了解有关客户端脚本的更多信息,请访问: https//system.na1.netsuite.com/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". 您需要做的第一件事是获取项目“修复”和“修复成本”的内部ID。

In this example, let's assumed that the internal id of Repair = 100 and Repair Cost = 200 在这个例子中,我们假设Repair = 100和Repair Cost = 200的内部id

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: 要了解套接字API以及销售订单中公开的字段,请查看此Netsuite帮助指南:

https://system.netsuite.com/help/helpcenter/en_US/RecordsBrowser/2012_2/Records/salesorder.html https://system.netsuite.com/help/helpcenter/en_US/RecordsBrowser/2012_2/Records/salesorder.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM