Skip to main content
Solved

Displaying field from another screen

  • October 27, 2021
  • 4 replies
  • 542 views

Forum|alt.badge.img

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

 

Best answer by Naveen Boga

Hi @ericklasimin61  The above code you have written with the SOOrderEntryExtension graph is correct, and but just add also one more condition i.e row !=null

public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
    protected void _(Events.FieldUpdated<SOLine, SOLine.inventoryID> e)
    {
        SOLine row = e.Row;
        if ( row!= null && row.InventoryID != null)
        {
            SOLineExt budgetext = row.GetExtension<SOLineExt>();
            InventoryItem item = InventoryItem.PK.Find(Base, row.InventoryID);
            budgetext.UsrTariffCode = item.HSTariffCode;
        }
    }
}

 

 

View original
Did this topic help you find an answer to your question?

4 replies

  • Freshman II
  • 14 replies
  • October 27, 2021

Hello @ericklasimin61 

 

Can you try with below code once.
 

 protected void _(Events.FieldUpdated<SOLine, SOLine.inventoryID> e)
        {
            SOLine row = e.Row;
            if (row.InventoryID != null)
            {
                InventoryItem item = InventoryItem.PK.Find(Base, row.InventoryID);
                SOLineExt budgetext = row.GetExtension<SOLineExt>();
                //or
                //SOLineExt headerExt = PXCache<Contract>.GetExtension<SOLineExt>(row);

                budgetext.usrTariffCode = item.HSTariffCode;
            }
        }

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 49 replies
  • October 29, 2021

Hi @ssamboju12 , I can’t seem to include the code in SOLineExt class as shown below

 

Should I use it in SOOrderEntry_Extension as shown below?

public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
    protected void _(Events.FieldUpdated<SOLine, SOLine.inventoryID> e)
    {
        SOLine row = e.Row;
        if (row.InventoryID != null)
        {
            InventoryItem item = InventoryItem.PK.Find(Base, row.InventoryID);
            SOLineExt budgetext = row.GetExtension<SOLineExt>();
            budgetext.UsrTariffCode = item.HSTariffCode;
        }
    }
}

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3399 replies
  • Answer
  • October 29, 2021

Hi @ericklasimin61  The above code you have written with the SOOrderEntryExtension graph is correct, and but just add also one more condition i.e row !=null

public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
    protected void _(Events.FieldUpdated<SOLine, SOLine.inventoryID> e)
    {
        SOLine row = e.Row;
        if ( row!= null && row.InventoryID != null)
        {
            SOLineExt budgetext = row.GetExtension<SOLineExt>();
            InventoryItem item = InventoryItem.PK.Find(Base, row.InventoryID);
            budgetext.UsrTariffCode = item.HSTariffCode;
        }
    }
}

 

 


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 49 replies
  • October 29, 2021

Hi @Naveen B & @ssamboju12 , thanks! It works like a charm! May I know if there is any pros and cons when using PXFormula instead of FieldUpdated?


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings