Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...