在Soline上将Salesperson ID设为必填字段

时间:2017-04-11 18:13:10

标签: acumatica

我需要在SOLine上将销售员ID作为必填字段。但由于转移订单没有销售员,因此只应在我创建转移订单以外的订单时进行验证。

我尝试使用下面的代码,但它似乎无法正常工作。可能会被现有的一些代码所覆盖。如果有人有任何建议,请告诉我。

public PXSetup<SOOrderTypeOperation,
	Where<SOOrderTypeOperation.orderType, Equal<Optional<SOOrderType.orderType>>,
	And<SOOrderTypeOperation.operation, Equal<Optional<SOOrderType.defaultOperation>>>>> sooperation;
			
protected bool IsTransferOrder
{
	get
	{
		return (sooperation.Current.INDocType == INTranType.Transfer);
	}
}

protected virtual void SOLine_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
	var row = (SOLine)e.Row;
	if (row == null) return;

	PXDefaultAttribute.SetPersistingCheck<SOLine.salesPersonID>(sender, row, IsTransferOrder ? PXPersistingCheck.Nothing : PXPersistingCheck.Null);
}

1 个答案:

答案 0 :(得分:0)

当条件存在时,我通常会在Row Persisting中抛出一个适当的异常。

以下是SOShipmentEntry检查传输和检查字段空值的示例:

protected virtual void SOShipment_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
    SOShipment doc = (SOShipment)e.Row;
    if (doc.ShipmentType == SOShipmentType.Transfer && doc.DestinationSiteID == null)
    {
        throw new PXRowPersistingException(typeof(SOOrder.destinationSiteID).Name, null, ErrorMessages.FieldIsEmpty, typeof(SOOrder.destinationSiteID).Name);
    }
}

我还在RowPersisting

中调用了类似于此示例的RaiseExceptionHandling
// sender = PXCache
if (row.OrderQty == Decimal.Zero)
    sender.RaiseExceptionHandling<POLine.orderQty>(row, row.OrderQty, new PXSetPropertyException(Messages.POLineQuantityMustBeGreaterThanZero, PXErrorLevel.Error));

两个示例都应该停止保存页面。调用Raise Exception处理应该指出带有Red X的字段,这是更好的方法,用户更容易找到有问题的字段。

对于你的例子:

protected virtual void SOLine_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
    SOLine row = (SOLine)e.Row;
    if (row == null)
    {
        return;
    }

    if (!IsTransferOrder && row.SalesPersonID == null)
    {
        sender.RaiseExceptionHandling<SOLine.salesPersonID>(row, row.SalesPersonID, new PXSetPropertyException(ErrorMessages.FieldIsEmpty, PXErrorLevel.Error));
    }
}
相关问题