Solved

How do I access a newly created user field in the summary section of Transfers from fielddefaulting for a field in the grid below?


Userlevel 5
Badge +1

I have added a field to the Transfers screen in the summary section.  This is a database field as below:

The intention is that this will be set to the default location which will be used by newly created entries in the grid below using fielddefaulting to set the value of location from this field.

I have a couple of questions. 

 

  1. How do I access this field’s value from the fielddefaulting event for Location?

I have previously accessed an extension to get a user field (SOOrderExt in that case) using: 

SOOrderExt sOOrderExt = PXCache<SOOrder>.GetExtension<SOOrderExt>(row);

 Using the same method to try to access the extension from INRegisterExt:

protected void INTran_LocationID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e, PXFieldDefaulting InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (INTran)e.Row;

if (row == null) return;

INRegisterExt iNRegisterExt = PXCache<INRegister>.GetExtension<INRegisterExt>(row);

e.NewValue = iNRegisterExt.UsrDefaultLocation;
}

gives error:

An object reference is required for the non-static field, method, or property 'PXCache<INRegister>.GetExtension<INRegisterExt>(object)'
  1. How do I add a selector to the field in Summary to choose a location from the list in INLocation for the MAIN warehouse?

Any help would be much appreciated.

Phil

icon

Best answer by Naveen Boga 4 June 2022, 06:58

View original

2 replies

Userlevel 7
Badge +17

Hi @ppowell  Can you please try like below and verify?

 

 public class INTransferEntryExt : PXGraphExtension<INTransferEntry>
{
protected void INTran_LocationID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e, PXFieldDefaulting InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(cache, e);
var row = (INTran)e.Row;
if (row != null)
{
INRegisterExt iNRegisterExt = Base.transfer.Current?.GetExtension<INRegisterExt>();
e.NewValue = iNRegisterExt?.UsrDefaultLocation;
}
}
}

 

Userlevel 5
Badge +1

@Naveen Boga, thanks for this.  It turns out I needed to convert the string to an int so I ended up with:

protected void INTran_LocationID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e, PXFieldDefaulting InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(cache, e);
var row = (INTran)e.Row;
if (row != null)
{
INRegisterExt iNRegisterExt = Base.transfer.Current?.GetExtension<INRegisterExt>();
e.NewValue = int.Parse(iNRegisterExt?.UsrDefaultLocation);
}
}

but I have it working now thanks to you.  I added the following selector:

public class mainWarehouse: PX.Data.Constant<string>
{
public mainWarehouse() : base("MAIN") { }
}

public class INRegisterExt : PXCacheExtension<PX.Objects.IN.INRegister>
{
#region UsrDefaultLocation
[PXDBString]
[PXUIField(DisplayName="Default Location",Visibility = PXUIVisibility.SelectorVisible)]
[PXSelector(typeof(
Search2<INLocation.locationID,
InnerJoin<INSite,
On<INSite.siteID, Equal<INLocation.siteID>,
And<INSite.siteCD, Equal<mainWarehouse>>>
>>)

, SubstituteKey = typeof(INLocation.locationCD)
, CacheGlobal = true)]
public virtual string UsrDefaultLocation { get; set; }
public abstract class usrDefaultLocation : PX.Data.BQL.BqlString.Field<usrDefaultLocation> { }
#endregion

It works but only after saving the record. I presume I need to get the value from the cache instead. How would I get the value from there instead?

 

Thanks for all your help,

 

Phil

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