Make Salesperson ID a Required field on SOLine

[亡魂溺海] 提交于 2019-12-12 06:09:02

问题


I need to make Salesperson ID on SOLine as a required field. But as Transfer orders do not have Salesperson, hence it should only validate when I create orders other than Transfer orders.

I tried with below code but it seems it is not working. Might be it is overrided with some existing code. Let me know if anyone has any suggestions.

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:


I usually thrown an appropriate exception in Row Persisting when the condition exists.

Here is an example from SOShipmentEntry checking for transfer and checking the null value of a field:

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);
    }
}

I have also called RaiseExceptionHandling similar to this example within RowPersisting

// sender = PXCache
if (row.OrderQty == Decimal.Zero)
    sender.RaiseExceptionHandling<POLine.orderQty>(row, row.OrderQty, new PXSetPropertyException(Messages.POLineQuantityMustBeGreaterThanZero, PXErrorLevel.Error));

Both examples should stop the page from the save. calling the Raise Exception handling should point out the field with the Red X which is the better approach and easier for the user to find the field in question.

For your example:

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));
    }
}


来源:https://stackoverflow.com/questions/43353360/make-salesperson-id-a-required-field-on-soline

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!