Netsuite脚本 - 更新自定义数量可用字段// location = warehouse

时间:2022-03-30 07:20:48

I am trying create a script so that it can update custom field with quantity available from "warehouse" location(we have multiple location). First i was trying to set value in the custom field but its not working. Code:

我正在尝试创建一个脚本,以便它可以使用“仓库”位置(我们有多个位置)的数量更新自定义字段。首先,我试图在自定义字段中设置值,但它不起作用。码:

{
var stdField = 'custitem_annaslinenssku'; // Custom field for quantity
var qtyAvail = 0;
qtyAvail = rec.getValue('locationquantityavailable');
}

function Qtyupdate()
{   
if(location == 1)
nlapiSetFieldValue(stdField,qtyAvail);
return true;
}

Then i wanted to add a logic like "if the quantity is less than 12 then script should make those item quantity 0.

然后我想添加一个逻辑,如果“如果数量小于12,那么脚本应该使这些项目数量为0。

I also wanted to add quantity available for kit/package item but totally no idea.

我还想添加可用于套件/包装件的数量,但完全不知道。

1 个解决方案

#1


2  

You might also want to share how you are using the information. It looks like you might be trying to set up an inventory reserve. You might be better off to create a reserve location and transfer inventory there. Then you can put your 12 items into the reserve location and make that not available for website.

您可能还想分享您使用这些信息的方式。看起来您可能正在尝试设置库存储备。您可能最好创建一个保留位置并在那里转移库存。然后,您可以将您的12个项目放入保留位置,并使其不适用于网站。

If that's not what you are tying to accomplish you might want to look at Netsuite's inventory management fields.

如果这不是你想要完成的事情,你可能想看看Netsuite的库存管理领域。

However to answer your question you can't normally get the inventory location fields from the item record so in a scheduled script you'd be doing something like the following. If you are running this from a user script beware of governance issues:

但是,要回答您的问题,您通常无法从项目记录中获取库存位置字段,因此在计划脚本中您将执行以下操作。如果从用户脚本运行此操作,请注意治理问题:

 var items = nlapiSearchRecord('inventoryitem', null, 
    [
        new nlobjSearchFilter('inventorylocation', null, 'is', 1), // your target inventory location internal id.
        new nlobjSearchFilter('isinactive', null, 'is', 'F'),
        new nlobjSearchFilter('locationavailable', null, 'lessthan', 13),
        new nlobjSearchFilter('custitem_my_custom_field', null, 'greaterthan', 0)
    ],[
        new nlobjSearchColumn('locationavailable'),
        new nlobjSearchColumn('custitem_my_custom_field')
    ]);
if(!items) return;
items.forEach(function(it){
    var customLevel = parseInt(it.getValue('locationavailable'), 10)||0;
    customLevel = Math.min(customLevel - 12, 0);
    if(customLevel == parseInt(it.getValue('custitem_my_custom_field'), 10)) return;
    nlapiSubmitField(it.getRecordType(), it.getId(), 'custitem_my_custom_field', customLevel);
});    

#1


2  

You might also want to share how you are using the information. It looks like you might be trying to set up an inventory reserve. You might be better off to create a reserve location and transfer inventory there. Then you can put your 12 items into the reserve location and make that not available for website.

您可能还想分享您使用这些信息的方式。看起来您可能正在尝试设置库存储备。您可能最好创建一个保留位置并在那里转移库存。然后,您可以将您的12个项目放入保留位置,并使其不适用于网站。

If that's not what you are tying to accomplish you might want to look at Netsuite's inventory management fields.

如果这不是你想要完成的事情,你可能想看看Netsuite的库存管理领域。

However to answer your question you can't normally get the inventory location fields from the item record so in a scheduled script you'd be doing something like the following. If you are running this from a user script beware of governance issues:

但是,要回答您的问题,您通常无法从项目记录中获取库存位置字段,因此在计划脚本中您将执行以下操作。如果从用户脚本运行此操作,请注意治理问题:

 var items = nlapiSearchRecord('inventoryitem', null, 
    [
        new nlobjSearchFilter('inventorylocation', null, 'is', 1), // your target inventory location internal id.
        new nlobjSearchFilter('isinactive', null, 'is', 'F'),
        new nlobjSearchFilter('locationavailable', null, 'lessthan', 13),
        new nlobjSearchFilter('custitem_my_custom_field', null, 'greaterthan', 0)
    ],[
        new nlobjSearchColumn('locationavailable'),
        new nlobjSearchColumn('custitem_my_custom_field')
    ]);
if(!items) return;
items.forEach(function(it){
    var customLevel = parseInt(it.getValue('locationavailable'), 10)||0;
    customLevel = Math.min(customLevel - 12, 0);
    if(customLevel == parseInt(it.getValue('custitem_my_custom_field'), 10)) return;
    nlapiSubmitField(it.getRecordType(), it.getId(), 'custitem_my_custom_field', customLevel);
});