Solved

Displaying field from another screen

  • 27 October 2021
  • 4 replies
  • 494 views

Userlevel 2
Badge

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

 

icon

Best answer by Naveen Boga 29 October 2021, 05:36

View original

4 replies

Userlevel 2

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

 

Userlevel 2
Badge

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

 

Userlevel 7
Badge +17

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

 

 

Userlevel 2
Badge

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


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved