Netsuite 在自定义字段中自动填充项目金额

Netsuite 在自定义字段中自动填充项目金额,netsuite,Netsuite,如何在现金销售的自定义字段中自动填充项目金额 我对客户端脚本还不熟悉,下面是我尝试过的代码片段,但它的功能不符合预期。请建议 function custItemAmount(type) { if(type == 'edit') { var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId()); var itemCount = record.getLineItem

如何在现金销售的自定义字段中自动填充项目金额

我对客户端脚本还不熟悉,下面是我尝试过的代码片段,但它的功能不符合预期。请建议

function custItemAmount(type) 
{   
    if(type == 'edit')
    {
        var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId());
        var itemCount = record.getLineItemCount('item');

        for(i=1; i<=itemCount; i++)
        {
            //fetch amount of each item
            var item_amount=record.getLineItemValue('item', 'amount', i);
            if (item_amount != null && item_amount != '') {
                record.setLineItemValue('item', 'custbody_itemamount', i, item_amount);
                //set total amount to custom item amount field
            }
        }
        var id = nlapiSubmitRecord(record, true);
    }
}
函数custItemAmount(类型)
{   
如果(类型==“编辑”)
{
var record=nlapiLoadRecord(nlapiGetRecordType(),nlapiGetRecordId());
var itemCount=record.getLineItemCount('item');

对于(i=1;i看起来您试图为行项目设置错误的字段。
custbody\u itemamount
真的是您想要的字段吗?对我来说似乎是一个body字段,而不是行项目字段。我希望它被称为
custcol\u lineitemamount

尽管我做了一些假设,请检查以确保字段名是正确的,但请尝试以下操作

{   
   if(type == 'edit')
   {
    var record = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId());
    var itemCount = record.getLineItemCount('item');

        for(i=1;i<=itemCount;i++)
        {
            //fetch amount of each item
            var item_amount=record.getLineItemValue('item', 'amount', i);
                if (item_amount != null && item_amount != '') {
                record.setLineItemValue('item', 'custcol_itemamount', i, item_amount);
        //set total amount to custom item amount field
                }
   }
var id = nlapiSubmitRecord(record, true);
}
{
如果(类型==“编辑”)
{
var record=nlapiLoadRecord(nlapiGetRecordType(),nlapiGetRecordId());
var itemCount=record.getLineItemCount('item');

对于(i=1;i何时希望看到填充的自定义列?是否在用户添加行之后?如果是,则您的脚本不正确。您共享的脚本看起来是用户事件脚本。这些类型的脚本仅在加载或保存记录时执行。

使用以下简单脚本解决。感谢您的帮助

== 函数custItemAmount(类型)

nlapiSetCurrentLineItemValue('item','custcol_item_amount',nlapiFormatCurrency(item_amount))

}

返回true;
}

看起来您试图为行项目设置错误的字段。
custbody\u itemamount
真的是您想要的字段吗?对我来说似乎是一个body字段,而不是行项目字段。我希望它被称为
custcol\u lineitemamount
Typo。这是正确的。是custcol\u lineitemamount。您看到脚本有任何问题吗?这是fi吗您要填充的eld是正文字段还是行项目字段?已对其进行了测试,但尚未看到正在填充的值。我是否遗漏了某些内容?脚本是否在验证行函数中工作?您是否可以测试并让我知道它是否工作?需要了解更多上下文。您希望何时自动填充值。例如,如果这是客户端脚本,为什么要加载记录来读取项目字段,而该字段应该已经在表单上可用?在客户端脚本下面进行了测试,但在自定义字段中没有更改。函数custItemAmount(type){if(type=='edit'){//迭代(i=1;i)的项目
{  
        if(type == 'item'){

    var item_amount=parseFloat(nlapiGetLineItemValue('item','amount'));   
    //nlapiSetFieldValue('custcol_item_amount',item_amount);