我正在尝试使用从我的edi系统检索的数据创建销售订单 . 我有代码工作来检索订单,但我在创建SO时遇到问题 . 我可以使用SOAP接口使用外部程序创建它们,但我尝试使用图形并直接插入它们 . 我得到一个异常,说明“{”错误:在处理字段CustomerLocationID期间发生错误:对象引用未设置为对象的实例..“}”但我成功查找了客户ID和位置ID . 这是我日常的代码 . 我使用类似的代码为我创建的新的主/详细表集创建记录 .
请告知是否有人以这种方式创建销售订单 . 该行引发错误:soOrder.CurrentDocument.Insert(order);
我也试图访问SOOrder和SOLine的扩展字段时出错 . 我目前评论这些字段是否可以创建订单,但我也需要在其中加载数据 .
foreach (LingoOrderSearch ediOrder in doc850)
{
res850 = lingo.Retrieve850(ediOrder.documentId, "850");
SOOrderEntry soOrder = PXGraph.CreateInstance();
soOrder.Clear();
var order = new SOOrder();
//SOOrderExt orderExt = order.GetExtension();
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();
Customer arCustomer = PXSelect>,
And>>>>.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();
Location arCustomerLocation = PXSelect>,
And>,
And>>>>>
.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();
InventoryItem invItem = PXSelect
Where>,
And>>>>
.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();
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);
}
}
}