我向SOShipment添加了一个自定义字段,我想在订单输入或流程订单屏幕上调用CreateShipment操作时设置其值。我该怎么做?
答案 0 :(得分:1)
为SOOrderEntry创建图表扩展,并添加如下的Action方法:
using PX.Data;
using System.Collections;
namespace PX.Objects.SO
{
public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
public PXAction<SOOrder> action;
[PXUIField(DisplayName = "Actions", MapEnableRights = PXCacheRights.Select)]
[PXButton]
protected virtual IEnumerable Action(PXAdapter adapter,
[PXInt]
[PXIntList(new int[] { 1, 2, 3, 4, 5 }, new string[] { "Create Shipment", "Apply Assignment Rules", "Create Invoice", "Post Invoice to IN", "Create Purchase Order" })]
int? actionID,
[PXDate]
DateTime? shipDate,
[PXSelector(typeof(INSite.siteCD))]
string siteCD,
[SOOperation.List]
string operation,
[PXString()]
string ActionName)
{
//actionID = 1 means the CreateShipment action was the one invoked
if (actionID == 1)
{
PXGraph.InstanceCreated.AddHandler<SOShipmentEntry>((graph) =>
{
graph.RowInserting.AddHandler<SOShipment>((sender, e) =>
{
//Custom logic goes here
var shipment = (SOShipment)e.Row;
var shipmentExt = PXCache<SOShipment>.GetExtension<SOShipmentExt>(shipment);
if (Base.Document.Current != null && shipmentExt != null)
{
shipmentExt.UsrPriority = Base.Document.Current.Priority;
}
});
});
}
//calls the basic action that was invoked
return Base.action.Press(adapter);
}
}
}
当运行任何SOOrderEntry操作时(即使通过Process Orders屏幕),也会调用此方法。我们使用actionID == 1
验证操作是否真的是CreateShipment,并为SOShipmentEntry图创建和SOShipment RowInserting添加事件处理程序。我们的自定义逻辑添加在RowInserting事件中。