Solved

Custom field not not showing value in Storage Summary

  • 21 December 2022
  • 11 replies
  • 269 views

Userlevel 2
Badge

Hi there,

 

I am having trouble to display the custom field value for Inventory Item Class in Storage Summary screen as shown below:

 

My DAC:

public class StoragePlaceStatusExt : PXCacheExtension<PX.Objects.IN.StoragePlaceStatus>
{
#region UsrItemClass
[PXDBString(30,BqlField=typeof(StoragePlaceExt.usrItemClass))]
[PXUIField(DisplayName = "Item Class")]

[PXDBScalar(typeof(Search2<INItemClass.itemClassCD,
InnerJoin<InventoryItem, On<InventoryItem.itemClassID, Equal<INItemClass.itemClassID>>>,
Where<InventoryItem.inventoryID, Equal<StoragePlaceStatus.inventoryID>>>))]

public virtual string UsrItemClass { get; set; }
public abstract class usrItemClass : PX.Data.BQL.BqlString.Field<usrItemClass> { }
#endregion
}

 

When I tried creating the field in Customization Project Editor screen, it seems like it was created in two places: StoragePlace and StoragePlaceStatus.

 

However, referring from the Element Inspector in Storage Summary screen, it is referring to only StoragePlaceStatus. Am I missing anything here?

icon

Best answer by andriikravetskyi35 21 December 2022, 16:59

View original

11 replies

Userlevel 5
Badge +1

Hi, 

As you try to extend DAC table that uses [PXProjection] attribute, it can be difficult to select data using PXScalar or PXFormula from DB, but it is real.

I think PXDependsOnField you can delete from code, I don’t try building code without it, but anyway it works as on screen-shot below.

 

Try to use this code:

  #region UsrItemClass
        [PXInt]
        [PXUIField(DisplayName = "Item Class")]
        [PXDependsOnFields(typeof(StoragePlaceStatus.inventoryID))]
        [PXSelector(typeof(SearchFor<INItemClass.itemClassID>),
            SubstituteKey = typeof(INItemClass.itemClassCD), DescriptionField = typeof(INItemClass.descr))]
        [PXParent(typeof(SelectFrom<InventoryItem>.Where<InventoryItem.inventoryID.IsEqual<StoragePlaceStatus.inventoryID.FromCurrent>>))]
        [PXFormula(typeof(Parent<InventoryItem.itemClassID>))]
        public virtual int? UsrItemClass { get; set; }
        public abstract class usrItemClass : PX.Data.BQL.BqlInt.Field<usrItemClass> { }
        #endregion 

 

 

Userlevel 2
Badge

Hi @andriikravetskyi35 , thanks for your response. The code works like a charm!

 

However, my end result is a bit different from yours despite running the same code as indicated above.

 

As you can see, my item class doesn’t show the description whereas yours does show it. Any ideas why?

Userlevel 7
Badge +8

@andriikravetskyi35

if you comment the below part of the DAC Ext you should get your desired result in the grid

 

SubstituteKey = typeof(INItemClass.itemClassCD), 

alternatively I guess there is property that you can choose for the field in the grid whether value or text should be displayed if I’m not mistaken 

Userlevel 5
Badge +1

For description in selector in one field, yes, we use SubstituteKey and Description field, and also preferences on aspx file.

 You need setup “DisplayMode” and select Hint in customization editor, here is example:

           


 

Userlevel 2
Badge

Both of you are right! I’ve changed the DisplayMode to Hint and it shows both Value and Text. Thanks a lot for this, really appreciate it!

Userlevel 2
Badge

Hi @andriikravetskyi35 & @aaghaei ,

 

It seems like 2023 R2 renders the code useless now - the Item Class column does not populate any value. I’ve tried alternatives such as:

  1. Calling a FieldUpdated event on Warehouse filter - the filter will be defaulted to blank again
  2. Reverted back to using PXDBScalar - Item Class column remains blank

However, both alternatives, as indicated above, does not work. Can anyone explain on why this happened and what other alternatives can I explore for this issue?

Userlevel 5
Badge +1

Hi, @ericklasimin61

Here DAC and Graph extensions, I change type of custom field from string to int, also add one event, and it works without attributes in DAC:

  public class StoragePlaceStatusExt : PXCacheExtension<PX.Objects.IN.StoragePlaceStatus>
{
public static bool IsActive() => true;

#region UsrItemClass
[PXInt()]
[PXUIField(DisplayName = "Item Class")]
[PXSelector(typeof(SearchFor<INItemClass.itemClassID>), SubstituteKey =typeof(INItemClass.itemClassCD), DescriptionField =typeof(INItemClass.descr))]
public virtual int? UsrItemClass { get; set; }
public abstract class usrItemClass : PX.Data.BQL.BqlInt.Field<usrItemClass> { }
#endregion
}

public class StoragePlaceEnqExt : PXGraphExtension<StoragePlaceEnq>
{
public static bool IsActive() => true;

protected virtual void _(Events.FieldSelecting<StoragePlaceStatus, StoragePlaceStatusExt.usrItemClass> e)
{
if (e.Row == null || e.Row.InventoryID == null) return;

var item = InventoryItem.PK.Find(Base, e.Row.InventoryID);
e.ReturnValue = item.ItemClassID;
e.Cache.SetValueExt<StoragePlaceStatusExt.usrItemClass>(e.Row, item.ItemClassID);
}
}

 

SetValueExt and e.ReturnValue - use both commands, in another way you will see only ItemClassCD on screen.

Screen shots of aspx and UI:

 

Userlevel 2
Badge

Hi @andriikravetskyi35 , the code works like a charm!

 

That’s kinda odd since previously, it works without the needs to trigger the event. And may I further ask on how does FieldSelecting logic work when the targeted field for the event is the usrItemClass itself? I was under the impression that the trigger must be interacted with for the event to take place.

 

For example, if I have a custom field in SOLine, I will usually insert FieldUpdated event on SOLine.InventoryID so that upon inserting the line, the custom field will be populated.

Userlevel 2
Badge

@andriikravetskyi35 Upon further testing, it seems like we are unable to filter any values from the generated column. I’ve tried pulling the other generated columns as well, but apparently they cannot be filtered as well. Any workaround for this?

Userlevel 5
Badge +1

hi @ericklasimin61 ,

idea with event was more efficient in prospective of performance, but as filtering isn’t working, I override delegate of view.

So try to run this, except event, on my local PC filtering start working:

 

 [PXOverride]
public virtual IEnumerable Storages(Func<IEnumerable> baseMethod)
{
var rows = baseMethod();

foreach (StoragePlaceStatus row in rows)
{
var item = InventoryItem.PK.Find(Base, row.InventoryID);

var rowExt = PXCache<StoragePlaceStatus>.GetExtension<StoragePlaceStatusExt>(row);
rowExt.UsrItemClass = item.ItemClassID;
}

return rows;
}

 

Userlevel 2
Badge

Hi @andriikravetskyi35 , the solution you provided works with the exception that the filtering only works for the current page.

 

However, I did manage to work around it by setting the AdjustPageSize to None and the PageSize to a value that is able to accommodate all of the records. So, at the end of the day, the issue is pretty much solved! Thanks a lot for your assistance, @andriikravetskyi35 !

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