Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

acumatica - Make Salesperson ID a Required field on SOLine

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);
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...