0
votes

I need to validate the selection of a proper location during PO Receipt, which may mean altering the "Default" location defined on the Item Warehouse screen on an ad hoc basis. My challenge is that the field defaulting event handler is defined within the POLocationAvailAttribute Attribute rather than the POReceiptEntry graph.

public class POLocationAvailAttribute : LocationAvailAttribute
{
    public POLocationAvailAttribute(Type InventoryType, Type SubItemType, Type SiteIDType, Type TranType, Type InvtMultType)
        : base(InventoryType, SubItemType, SiteIDType, TranType, InvtMultType)
    {
    }

    public override void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
    {
        POReceiptLine row = e.Row as POReceiptLine;
        if (row == null) return;

        if (POLineType.IsStock(row.LineType) && row.POType != null && row.PONbr != null && row.POLineNbr != null)
        {
            POLine poLine = PXSelect<POLine, Where<POLine.orderType, Equal<Required<POLine.orderType>>,
                    And<POLine.orderNbr, Equal<Required<POLine.orderNbr>>,
                    And<POLine.lineNbr, Equal<Required<POLine.lineNbr>>>>>>.Select(sender.Graph, row.POType, row.PONbr, row.POLineNbr);

            if (poLine != null && poLine.TaskID != null)
            {
                INLocation selectedLocation = PXSelect<INLocation, Where<INLocation.siteID, Equal<Required<INLocation.siteID>>,
                    And<INLocation.taskID, Equal<Required<INLocation.taskID>>>>>.Select(sender.Graph, row.SiteID, poLine.TaskID);

                if (selectedLocation != null )
                {
                    e.NewValue = selectedLocation.LocationID;
                    return;
                }
                else
                {
                    e.NewValue = null;
                    return;
                }
            }
        }

        base.FieldDefaulting(sender, e);
    }
}

How do I override the Field Defaulting event within my Graph Extension so that the Base Method is called to set the default location, but then I can check to see if it needs to be toggled to my "alternate default location" when my specific conditions are met?

1

1 Answers

2
votes

Easy

First: you derrive from POLocationAvailAttribute with yo'ure own attribute and override FieldDefaulting method.

public class CustomPOLocationAvailAttribute : POLocationAvailAttribute
{
    public CustomPOLocationAvailAttribute(Type InventoryType, Type SubItemType, Type SiteIDType, Type TranType, Type InvtMultType)
        : base(InventoryType, SubItemType, SiteIDType, TranType, InvtMultType)
    {
    }

    public override void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
    {
        base.FieldDefaulting(sender, e);
        //code you may wanna implement          
    }
}

Second: extend the POReceiptLine DAC and replace the existing attribute with custom one.

public class POReceiptLineExt : PXCacheExtension<POReceiptLine>
{
        #region LocationID
        public abstract class locationID : PX.Data.IBqlField        {       }
        [PXMergeAttributes(Method = MergeMethod.Append)]
        [PXRemoveBaseAttribute(typeof(POLocationAvailAttribute))]
        [CustomPOLocationAvail(typeof(POReceiptLine.inventoryID), typeof(POReceiptLine.subItemID), typeof(POReceiptLine.siteID), typeof(POReceiptLine.tranType), typeof(POReceiptLine.invtMult), KeepEntry = false)]
        public virtual Int32? LocationID {get; set;}
        #endregion
}

Attention: You may override the Attribute: - at Graph Level with CacheAttached event, to apply the changes only on that screen. - or at DAC level to apply changes at all screens that use POReceiptLine DAC object.

Should work now ;)