从另一个绑定的自定义字段填充未绑定的字段

时间:2018-01-11 19:23:54

标签: acumatica

我要求在SalesOrder屏幕上有一个字段,并且相同的字段也应出现在Shipment屏幕上,也用于相应的SalesOrder。并且用户应该能够在屏幕上更新这些字段。

我在“销售订单”屏幕上创建了一个绑定字段,用户可以将其保存。然后我在“货件”屏幕上创建了一个未绑定的字段,以显示“销售订单”中的文本。为此,我编写了一个SOShipment_RowSelected事件,稍后用户将其更新到数据库,我写了SOShipment_RowUpdated。但是,当我尝试编辑该字段时,它会触发RowSelected事件并覆盖编辑并返回相同的原始值。

我尝试过SOShipment_ShipmentNbr_FieldUpdated& SOShipment_ShipmentNbr_FieldUpdating事件但每次都没有触发。

以下是缓存扩展的代码 -

public class SOOrderExtension : PXCacheExtension<SOOrder>
{
	#region UsrNotesText
	[PXDBString(255)]
	[PXUIField(DisplayName = "Pick List Notes")]
	public virtual string UsrNotesText { get; set; }
	public abstract class usrNotesText : IBqlField { }
	#endregion
}
	
public class SOShipmentExtension : PXCacheExtension<SOShipment>
{
	#region UsrNotesText
	[PXString(255)]
	[PXUIField(DisplayName = "Pick List Notes")]
	public virtual string UsrNotesText { get; set; }
	public abstract class usrNotesText : IBqlField { }
	#endregion
}

SOShipmentExtension代码 -

public class SOShipmentEntryExtension : PXGraphExtension<SOShipmentEntry>
{
	PXSelect<SOOrder> soOrder;

	protected virtual void SOShipment_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
	{
		if (e.Row != null)
		{
			SOOrder order = PXSelectJoin<SOOrder,
				LeftJoin<SOOrderShipment, On<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>,
					And<SOOrder.orderType, Equal<SOOrderShipment.orderType>>>,
				LeftJoin<SOShipment, On<SOOrderShipment.shipmentNbr, Equal<SOShipment.shipmentNbr>>>>,
				Where<SOShipment.shipmentNbr, Equal<Current<SOShipment.shipmentNbr>>>>.Select(Base);

			if (order != null)
			{
				SOOrderExtension orderExt = PXCache<SOOrder>.GetExtension<SOOrderExtension>(order);

				SOShipment soShipment = Base.Document.Current;

				SOShipmentExtension ext = PXCache<SOShipment>.GetExtension<SOShipmentExtension>(soShipment);
				ext.UsrNotesText = orderExt.UsrNotesText;
			}
		}
	}

	protected virtual void SOShipment_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
	{
		SOShipment oldRow = (SOShipment)e.OldRow;
		SOShipment newRow = (SOShipment)e.Row;

		if (oldRow != null || newRow != null)
		{
			SOShipmentExtension oldExt = PXCache<SOShipment>.GetExtension<SOShipmentExtension>(oldRow);
			SOShipmentExtension newExt = PXCache<SOShipment>.GetExtension<SOShipmentExtension>(newRow);


			if (oldExt.UsrNotesText != newExt.UsrNotesText)
			{
				{
					SOOrder order = PXSelectJoin<SOOrder,
					LeftJoin<SOOrderShipment, On<SOOrder.orderNbr, Equal<SOOrderShipment.orderNbr>,
						And<SOOrder.orderType, Equal<SOOrderShipment.orderType>>>,
					LeftJoin<SOShipment, On<SOOrderShipment.shipmentNbr, Equal<SOShipment.shipmentNbr>>>>,
					Where<SOShipment.shipmentNbr, Equal<Current<SOShipment.shipmentNbr>>>>.Select(Base);

					soOrder.Current = order;

					if (order != null)
					{
						SOOrderExtension orderExt = PXCache<SOOrder>.GetExtension<SOOrderExtension>(order);

						orderExt.UsrNotesText = newExt.UsrNotesText;
						soOrder.Update(order);
					}
				}
			}
		}
	}
}

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

诀窍是在别处初始化UsrNotesText。

您可以使用PXDefault属性:

[PXDefault(typeof(Search<SOOrderExtension.usrNotesText, Where< [...] >>))]

或FieldDefaulting事件处理程序:

public void SOShipment_UsrNotesText_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
   e.NewValue = [...]
}

有时您还想在用户更改未重新触发默认值的关键字段时重新初始化。:

public void SOShipment_ShipmentNbr_FieldUpdated(PXCache sender, PXFieldDefaultingEventArgs e)
{
    SOShipment shipment = e.Row as SOShipment;

    if (shipment != null)
    {
        SOShipmentExtension shipmentExt = PXCache<SOShipment>.GetExtension<SOShipmentExtension>(shipment);

        if (shipmentExt != null)
        {
            shipmentExt.UsrNotesText = [...];
        }
    }
}

在这种情况下,使用RaiseFieldDefaulting手动重新触发FieldDefaulting事件通常是更好的选择。

但是,您选择初始化的方法是避免在RowSelected中设置字段值,因为当您不想初始化自定义字段时会调用该事件。