如何 access/expose Suitescript 中的库存项目位置子列表字段
How to access/expose Inventory Item Locations sublist fields in Suitescript
我启用了多位置功能和多位置库存。我需要一种方法来设置或检索特定于位置的值,例如现有位置、位置下一次盘点日期、位置上次盘点日期、位置库存盘点间隔。
这些字段可通过保存的搜索界面访问,但 SuiteAnswers 上没有关于如何通过 SuiteScript APIs 获取它们的文档。 SuiteScript Records 浏览器没有用于访问此子列表的条目。如何在不使用搜索的情况下使用 SuiteScript API 设置或检索值?
具体来说,我希望能够加载记录,为特定位置设置下一次库存盘点日期,然后提交并关闭并实际看到 Netsuite 中的更改。目前我发现的唯一解决方法是笨拙地在 suitescript 中构建一个 CSV 文件并将其提交给作业管理器,但这有其自身的局限性。
子列表名称未记录且不受官方支持,但您仍然可以使用子列表 ID "locations"、IE
访问它
//load arbitrary item record
var itemRec = nlapiLoadRecord('inventoryitem', 655009)
//find the line with location internal ID 1
var line = itemRec.findLineItemValue('locations','location',1);
//get that line's location count interval
var countinterval = itemRec.getLineItemValue('locations', 'invtcountinterval', line);
//calculate the next count date as today + interval, set up the
//last count date as a string
var lastCountDate = nlapiDateToString(new Date());
var nextCountDate = new Date() + countInterval*MILLISECONDS_IN_DAY;
nextCountDate = nlapiDateToString(nextCountDate);
//set the values on the item
itemRec.setLineItemValue('locations','lastinvtcountdate', line, lastCountDate);
itemRec.setLineItemvalue('locations','nextinvtcountdate', line, nextCountDate);
nlapiSubmitRecord(itemRec);
您可以在子列表界面上使用 chrome 中的 "Inspect Element" 之类的内容来发现子列表的字段名称。例如,右键单击任何项目的位置子列表上的 "Next Inventory Count Date" header,然后单击 "Inspect Element"。查看出现的 div.listheader,在其上方您会看到类似
的内容
.elements['locationssortfld'].value='nextinvtcountdate'
'nextinvtcountdate' 将是您插入到 nlapiSetLineItemValue 的字段参数中的字段 ID。
希望对某人有所帮助。我第一次自己解决这个问题时遇到了麻烦,虽然现在看起来更明显了。
您还可以使用这些字段 ID 从搜索中访问所需的字段。
new nlobjSearchColumn("locationquantityavailable",null,null)
new nlobjSearchColumn("locationquantityonhand",null,null)
new nlobjSearchColumn("locationlastinvtcountdate",null,null,
new nlobjSearchColumn("locationnextinvtcountdate",null,null)
new nlobjSearchColumn("locationinvtcountinterval",null,null)
我启用了多位置功能和多位置库存。我需要一种方法来设置或检索特定于位置的值,例如现有位置、位置下一次盘点日期、位置上次盘点日期、位置库存盘点间隔。
这些字段可通过保存的搜索界面访问,但 SuiteAnswers 上没有关于如何通过 SuiteScript APIs 获取它们的文档。 SuiteScript Records 浏览器没有用于访问此子列表的条目。如何在不使用搜索的情况下使用 SuiteScript API 设置或检索值?
具体来说,我希望能够加载记录,为特定位置设置下一次库存盘点日期,然后提交并关闭并实际看到 Netsuite 中的更改。目前我发现的唯一解决方法是笨拙地在 suitescript 中构建一个 CSV 文件并将其提交给作业管理器,但这有其自身的局限性。
子列表名称未记录且不受官方支持,但您仍然可以使用子列表 ID "locations"、IE
访问它//load arbitrary item record
var itemRec = nlapiLoadRecord('inventoryitem', 655009)
//find the line with location internal ID 1
var line = itemRec.findLineItemValue('locations','location',1);
//get that line's location count interval
var countinterval = itemRec.getLineItemValue('locations', 'invtcountinterval', line);
//calculate the next count date as today + interval, set up the
//last count date as a string
var lastCountDate = nlapiDateToString(new Date());
var nextCountDate = new Date() + countInterval*MILLISECONDS_IN_DAY;
nextCountDate = nlapiDateToString(nextCountDate);
//set the values on the item
itemRec.setLineItemValue('locations','lastinvtcountdate', line, lastCountDate);
itemRec.setLineItemvalue('locations','nextinvtcountdate', line, nextCountDate);
nlapiSubmitRecord(itemRec);
您可以在子列表界面上使用 chrome 中的 "Inspect Element" 之类的内容来发现子列表的字段名称。例如,右键单击任何项目的位置子列表上的 "Next Inventory Count Date" header,然后单击 "Inspect Element"。查看出现的 div.listheader,在其上方您会看到类似
的内容.elements['locationssortfld'].value='nextinvtcountdate'
'nextinvtcountdate' 将是您插入到 nlapiSetLineItemValue 的字段参数中的字段 ID。
希望对某人有所帮助。我第一次自己解决这个问题时遇到了麻烦,虽然现在看起来更明显了。
您还可以使用这些字段 ID 从搜索中访问所需的字段。
new nlobjSearchColumn("locationquantityavailable",null,null)
new nlobjSearchColumn("locationquantityonhand",null,null)
new nlobjSearchColumn("locationlastinvtcountdate",null,null,
new nlobjSearchColumn("locationnextinvtcountdate",null,null)
new nlobjSearchColumn("locationinvtcountinterval",null,null)