我正在尝试使用从我的edi系统检索的数据创建销售订单。我有代码工作来检索订单,但我在创建SO时遇到问题。我可以使用SOAP接口使用外部程序创建它们,但我尝试使用图形并直接插入它们。我得到一个异常,说明“{”错误:在处理字段CustomerLocationID期间发生错误:对象引用未设置为对象的实例..“}”但我成功查找了客户ID和位置ID。这是我日常的代码。我使用类似的代码为我创建的新的主/详细表集创建记录。
请告知是否有人以这种方式了解销售订单。该行引发错误: soOrder.CurrentDocument.Insert(顺序);
我在尝试访问SOOrder和SOLine的扩展字段时也遇到错误。我目前评论这些字段是否可以创建订单,但我也需要在其中加载数据。
foreach (LingoOrderSearch ediOrder in doc850)
{
res850 = lingo.Retrieve850(ediOrder.documentId, "850");
SOOrderEntry soOrder = PXGraph.CreateInstance<SOOrderEntry>();
soOrder.Clear();
var order = new SOOrder();
//SOOrderExt orderExt = order.GetExtension<SOOrderExt>();
order.OrderType = "SO";
order.Status = "Open";
if (res850.Data850.partner == "BEDBATH" || res850.Data850.partner == "BEDBATH_CAN")
customerLookup = "BBB";
else
customerLookup = res850.Data850.partner;
CustomerMaint customerGraph = PXGraph.CreateInstance<CustomerMaint>();
Customer arCustomer = PXSelect<Customer, Where<Customer.status, Equal<Required<Customer.status>>,
And<Customer.acctCD, Equal<Required<Customer.acctCD>>>>>.Select(this, "Active", customerLookup);
if (arCustomer == null)
throw new PXException("Unable to find customer " + customerLookup + " (partner:" + res850.Data850.partner + ")");
order.CustomerID = arCustomer.BAccountID;
CustomerLocationMaint customerLocationGraph = PXGraph.CreateInstance<CustomerLocationMaint>();
Location arCustomerLocation = PXSelect<Location, Where<Location.isActive, Equal<Required<Location.isActive>>,
And<Location.bAccountID, Equal<Required<Location.bAccountID>>,
And<Location.locationCD, Equal<Required<Location.locationCD>>>>>>
.Select(this, true, arCustomer.BAccountID, res850.Data850.location);
if (arCustomerLocation == null)
throw new PXException("Unable to find customer location" + customerLookup + " / " +
res850.Data850.location + " (partner:" + res850.Data850.partner + ")");
order.CustomerLocationID = arCustomerLocation.LocationID;
order.CustomerOrderNbr = res850.Data850.poNumber;
order.ExtRefNbr = res850.Data850.documentId.ToString();
//orderExt.UsrEDICustomerVendorId = res850.Data850.vendor;
//orderExt.UsrEDICustomerId = res850.Data850.partner;
if (!DateTime.TryParse(res850.Data850.poDate, out tempDate))
{
tempDate = DateTime.Today;
}
order.DocDate = tempDate;
DateTime.TryParse(res850.Data850.requestedDeliveryDate, out tempDate);
if (!DateTime.TryParse(res850.Data850.requestedDeliveryDate, out tempDate))
{
tempDate = DateTime.Today;
}
order.RequestDate = tempDate;
soOrder.CurrentDocument.Insert(order);
soOrder.Persist();
newOrderId = soOrder.CurrentDocument.Current.OrderNbr;
itemList = res850.Data850.items;
foreach (EdiDoc850Lingoitems item in itemList)
{
InventoryItemMaint invItemGraph = PXGraph.CreateInstance<InventoryItemMaint>();
InventoryItem invItem = PXSelect<InventoryItem,
Where<InventoryItem.itemStatus, Equal<Required<InventoryItem.itemStatus>>,
And<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>>
.Select(this, "Active", item.vendorItem);
if (invItem == null)
throw new PXException("Unable to locate item " + item.vendorItem);
var line = new SOLine();
//SOLineExt lineExt = line.GetExtension<SOLineExt>();
line.OrderNbr = newOrderId;
line.InventoryID = invItem.InventoryID;
line.Qty = item.qtyOrder;
line.ShipComplete = "Ship Complete";
Int32 tempLine = 0;
if (Int32.TryParse(item.lineNo, out tempLine)) { };
//lineExt.UsrEDILineNbr = tempLine;
soOrder.Transactions.Insert(line);
}
}
}
答案 0 :(得分:2)
希望以下示例有助于推进您的任务:
SOOrderEntry soOrder = PXGraph.CreateInstance<SOOrderEntry>();
var order = new SOOrder();
order.OrderType = SOOrderTypeConstants.SalesOrder;
order = soOrder.CurrentDocument.Insert(order);
Customer arCustomer = PXSelect<Customer, Where<Customer.status, Equal<Required<Customer.status>>,
And<Customer.acctCD, Equal<Required<Customer.acctCD>>>>>.Select(this, "Active", "ABARTENDE");
if (arCustomer == null)
throw new PXException("Unable to find customer");
order.CustomerID = arCustomer.BAccountID;
order = soOrder.CurrentDocument.Update(order);
Location arCustomerLocation = PXSelect<Location, Where<Location.isActive, Equal<Required<Location.isActive>>,
And<Location.bAccountID, Equal<Required<Location.bAccountID>>,
And<Location.locationCD, Equal<Required<Location.locationCD>>>>>>
.Select(this, true, arCustomer.BAccountID, "CHICAGO");
if (arCustomerLocation == null)
throw new PXException("Unable to find customer location");
order.CustomerLocationID = arCustomerLocation.LocationID;
order.CustomerOrderNbr = "res850.Data850.poNumber";
order.ExtRefNbr = "res850.Data850.documentId";
order.RequestDate = DateTime.Today;
soOrder.CurrentDocument.Update(order);
for(int i = 0; i < 3; i++)
{
InventoryItem invItem = PXSelect<InventoryItem,
Where<InventoryItem.itemStatus, Equal<Required<InventoryItem.itemStatus>>,
And<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>>
.Select(this, "Active", "AALEGO500");
if (invItem == null)
throw new PXException("Unable to locate item");
var line = soOrder.Transactions.Insert();
line.InventoryID = invItem.InventoryID;
line.Qty = 1;
line.ShipComplete = SOShipComplete.ShipComplete;
soOrder.Transactions.Update(line);
}
soOrder.Actions.PressSave();