无法在创建装运操作时将 UDF 从 SOLine (SO301000) 复制到 SOShipLine(SO302000)
Unable to Copy UDF from SOLine (SO301000) to SOShipLine(SO302000) on Create Shipment Action
我在 SOLine 和 SOShipLine 中创建了 2 个 UDF,我试图在“创建货件”操作中将这些 UDF 的值从 SOLine 复制到 SOShipLine。我的代码正在执行,但值没有被复制。我不确定“SOShipment_RowPersisting”是否是一种正确的方法,或者是否有任何其他方法可以解决这个问题。虽然这个 RowPersisting 对我有用,可以将字段从 POOrder 复制到 APInvoice,但请提出建议,谢谢
以下是我的代码:
public class SOShipmentEntry_Extension : PXGraphExtension<SOShipmentEntry>
{
#region Event Handlers
protected void SOShipment_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
{
var row = (SOShipment)e.Row;
SOShipLine row1 = new SOShipLine();
if (Base.Document.Current != null)
{
foreach (SOShipLine tran in Base.Transactions.Select())
{
SOLine xSOLine = PXSelect<SOLine,
Where<SOLine.orderNbr, Equal<Current<SOLine.orderNbr>>,
And<SOLine.orderType, Equal<Current<SOLine.orderType>>>>>.Select(Base, tran.OrigOrderNbr, tran.OrigOrderNbr);
if (xSOLine != null)
{
SOLineExt soLineExt = PXCache<SOLine>.GetExtension<SOLineExt>(xSOLine);
SOShipLineExt soShipLineExt = PXCache<SOShipLine>.GetExtension<SOShipLineExt>(row1);
soShipLineExt.UsrTerms = soLineExt.UsrTerms;
soShipLineExt.UsrWarrantyDate = soLineExt.UsrCustWarrDate;
}
return;
}
}
}
}
从一个文档复制到另一个文档时,我尽量远离文档事件,因为即使在创建文档后它们也会执行。因此,我总是尝试在创建文档的过程中挂接一个方法。
在您的情况下,您可以覆盖 SOShipmentEntry 图中的“CreateShipmentFromSchedules”方法并将您的代码移到那里。这将挂钩您的代码以仅在从 SO 转换为装运时执行。
public delegate Boolean CreateShipmentFromSchedulesDelegate(PXResult<SOShipmentPlan, SOLineSplit,
SOLine, InventoryItem, INLotSerClass, INSite, SOShipLine> res, SOShipLine newline, SOOrderType ordertype,
String operation, DocumentList<SOShipment> list);
[PXOverride]
public Boolean CreateShipmentFromSchedules(PXResult<SOShipmentPlan, SOLineSplit, SOLine,
InventoryItem, INLotSerClass, INSite, SOShipLine> res, SOShipLine newline, SOOrderType ordertype,
String operation, DocumentList<SOShipment> list, CreateShipmentFromSchedulesDelegate baseMethod)
{
if (res != null && newline != null)
{
SOShipLineExt soShipLineExt = PXCache<SOShipLine>.GetExtension<SOShipLineExt>(newline);
SOLine line = (SOLine)res;
SOLineExt soLineExt = PXCache<SOLine>.GetExtension<SOLineExt >(line);
soShipLineExt.UsrTerms = soLineExt.UsrTerms;
soShipLineExt.UsrWarrantyDate = soLineExt.UsrCustWarrDate;
}
return baseMethod(res, newline, ordertype, operation, list);
}
我在 SOLine 和 SOShipLine 中创建了 2 个 UDF,我试图在“创建货件”操作中将这些 UDF 的值从 SOLine 复制到 SOShipLine。我的代码正在执行,但值没有被复制。我不确定“SOShipment_RowPersisting”是否是一种正确的方法,或者是否有任何其他方法可以解决这个问题。虽然这个 RowPersisting 对我有用,可以将字段从 POOrder 复制到 APInvoice,但请提出建议,谢谢
以下是我的代码:
public class SOShipmentEntry_Extension : PXGraphExtension<SOShipmentEntry>
{
#region Event Handlers
protected void SOShipment_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
{
var row = (SOShipment)e.Row;
SOShipLine row1 = new SOShipLine();
if (Base.Document.Current != null)
{
foreach (SOShipLine tran in Base.Transactions.Select())
{
SOLine xSOLine = PXSelect<SOLine,
Where<SOLine.orderNbr, Equal<Current<SOLine.orderNbr>>,
And<SOLine.orderType, Equal<Current<SOLine.orderType>>>>>.Select(Base, tran.OrigOrderNbr, tran.OrigOrderNbr);
if (xSOLine != null)
{
SOLineExt soLineExt = PXCache<SOLine>.GetExtension<SOLineExt>(xSOLine);
SOShipLineExt soShipLineExt = PXCache<SOShipLine>.GetExtension<SOShipLineExt>(row1);
soShipLineExt.UsrTerms = soLineExt.UsrTerms;
soShipLineExt.UsrWarrantyDate = soLineExt.UsrCustWarrDate;
}
return;
}
}
}
}
从一个文档复制到另一个文档时,我尽量远离文档事件,因为即使在创建文档后它们也会执行。因此,我总是尝试在创建文档的过程中挂接一个方法。
在您的情况下,您可以覆盖 SOShipmentEntry 图中的“CreateShipmentFromSchedules”方法并将您的代码移到那里。这将挂钩您的代码以仅在从 SO 转换为装运时执行。
public delegate Boolean CreateShipmentFromSchedulesDelegate(PXResult<SOShipmentPlan, SOLineSplit,
SOLine, InventoryItem, INLotSerClass, INSite, SOShipLine> res, SOShipLine newline, SOOrderType ordertype,
String operation, DocumentList<SOShipment> list);
[PXOverride]
public Boolean CreateShipmentFromSchedules(PXResult<SOShipmentPlan, SOLineSplit, SOLine,
InventoryItem, INLotSerClass, INSite, SOShipLine> res, SOShipLine newline, SOOrderType ordertype,
String operation, DocumentList<SOShipment> list, CreateShipmentFromSchedulesDelegate baseMethod)
{
if (res != null && newline != null)
{
SOShipLineExt soShipLineExt = PXCache<SOShipLine>.GetExtension<SOShipLineExt>(newline);
SOLine line = (SOLine)res;
SOLineExt soLineExt = PXCache<SOLine>.GetExtension<SOLineExt >(line);
soShipLineExt.UsrTerms = soLineExt.UsrTerms;
soShipLineExt.UsrWarrantyDate = soLineExt.UsrCustWarrDate;
}
return baseMethod(res, newline, ordertype, operation, list);
}