如何使用自定义字段搜索 NetSuite 库存项目?
How do I search for NetSuite inventory items using a custom field?
使用 NetSuite 2020.1 网络服务,我想按名称和目录代码搜索库存项目(自定义 字段) .
这是我试图通过 code:
复制的搜索行为的屏幕截图
这是我在代码方面的智慧 (C#):
private string Exists(MapInvItem mapInvItem, ref InventoryItem inventoryItem)
{
string sRetrunValue = ITEM_NOTFOUND;
ItemSearch invSearch = new ItemSearch();
SearchCustomField[] searchCustomFields = new SearchCustomField[]
{
new SearchStringCustomField()
{
@operator = SearchStringFieldOperator.@is,
operatorSpecified = true,
searchValue = mapInvItem.catalogcode,
scriptId = CATALOG_CODE_NSID
}
};
SearchStringField name = new SearchStringField();
name.@operator = SearchStringFieldOperator.@is;
name.operatorSpecified = true;
name.searchValue = mapInvItem.sku;
ItemSearchBasic invBasic = new ItemSearchBasic();
invBasic.displayName = name;
invBasic.customFieldList = searchCustomFields;
invSearch.basic = invBasic;
SearchResult result = Client.Service.search(invSearch);
if (result.status.isSuccess)
{
if (result.totalRecords == 1)
{
// one item found => good to go
Record[] records = result.recordList;
inventoryItem = (InventoryItem)records[0];
sRetrunValue = inventoryItem.internalId;
}
else if (result.totalRecords > 1)
{
// more than one item, we may have a problem
Record[] records;
List<InventoryItem> inventoryItems = new List<InventoryItem>();
// Loop thru page count
for (int lpc = 0; lpc <= result.totalPages - 1; lpc++)
{
records = result.recordList;
for (int lcv = 0; lcv <= records.Length - 1; lcv++)
{
inventoryItems.Add((InventoryItem)records[lcv]);
return ((InventoryItem)records[lcv]).internalId;
}
}
}
}
else
{
// log failure
}
return sRetrunValue;
}
请注意,对于 result.status.isSuccess,我得到 true,但是 totalRecords 是 零。
使用 itemId 代替 displayName invBasic.itemId = name;
使用 NetSuite 2020.1 网络服务,我想按名称和目录代码搜索库存项目(自定义 字段) .
这是我试图通过 code:
复制的搜索行为的屏幕截图这是我在代码方面的智慧 (C#):
private string Exists(MapInvItem mapInvItem, ref InventoryItem inventoryItem)
{
string sRetrunValue = ITEM_NOTFOUND;
ItemSearch invSearch = new ItemSearch();
SearchCustomField[] searchCustomFields = new SearchCustomField[]
{
new SearchStringCustomField()
{
@operator = SearchStringFieldOperator.@is,
operatorSpecified = true,
searchValue = mapInvItem.catalogcode,
scriptId = CATALOG_CODE_NSID
}
};
SearchStringField name = new SearchStringField();
name.@operator = SearchStringFieldOperator.@is;
name.operatorSpecified = true;
name.searchValue = mapInvItem.sku;
ItemSearchBasic invBasic = new ItemSearchBasic();
invBasic.displayName = name;
invBasic.customFieldList = searchCustomFields;
invSearch.basic = invBasic;
SearchResult result = Client.Service.search(invSearch);
if (result.status.isSuccess)
{
if (result.totalRecords == 1)
{
// one item found => good to go
Record[] records = result.recordList;
inventoryItem = (InventoryItem)records[0];
sRetrunValue = inventoryItem.internalId;
}
else if (result.totalRecords > 1)
{
// more than one item, we may have a problem
Record[] records;
List<InventoryItem> inventoryItems = new List<InventoryItem>();
// Loop thru page count
for (int lpc = 0; lpc <= result.totalPages - 1; lpc++)
{
records = result.recordList;
for (int lcv = 0; lcv <= records.Length - 1; lcv++)
{
inventoryItems.Add((InventoryItem)records[lcv]);
return ((InventoryItem)records[lcv]).internalId;
}
}
}
}
else
{
// log failure
}
return sRetrunValue;
}
请注意,对于 result.status.isSuccess,我得到 true,但是 totalRecords 是 零。
使用 itemId 代替 displayName invBasic.itemId = name;