I have created one custom field each in Sales Orders screen and in Add SO Line dialog box in Invoices screen to display the value of Tariff Code in Stock Items screen. I managed to display them using the code below:
public class SOLineExt : PXCacheExtension<PX.Objects.SO.SOLine>
{
#region UsrTariffCode
[PXDBString(30)]
[PXUIField(DisplayName = "Tariff Code", Enabled = false)]
[PXFormula(typeof(Selector<SOLine.inventoryID,InventoryItem.hSTariffCode>))]
public virtual string UsrTariffCode { get; set; }
public abstract class usrTariffCode : PX.Data.BQL.BqlString.Field<usrTariffCode> { }
#endregion
}
public class SOLineForDirectInvoiceExt : PXCacheExtension<PX.Objects.SO.DAC.Projections.SOLineForDirectInvoice>
{
#region UsrTariffCode
[PXDBString(50, BqlField = typeof(SOLineExt.usrTariffCode))]
[PXUIField(DisplayName = "Tariff Code", Enabled = false)]
public virtual string UsrTariffCode { get; set; }
public abstract class usrTariffCode : PX.Data.BQL.BqlString.Field<usrTariffCode> { }
#endregion
}
Is there an alternative way of doing this via FieldUpdated or FieldDefaulting method?
I have tried inserting the code below in SOLineExt class but failed to get the desired result:
protected void _(Events.FieldUpdated<SOLine, SOLine.inventoryID> e)
{
SOLine row = e.Row;
if (row.InventoryID != null)
{
InventoryItem item = PXSelectorAttribute.Select<SOLine.inventoryID>(e.Cache, row) as InventoryItem;
e.Cache.SetValueExt<SOLineExt.usrTariffCode>(row, item.HSTariffCode);
}
}