Solved

Is there an attribute that merges StockItem with CrossItem?

  • 6 April 2021
  • 4 replies
  • 153 views

Userlevel 7
Badge +5

I would like to support barcode/cross-reference in the Inventory ID field on the Transfers screen.

The POReceiptLine.inventoryID is decorated with [POReceiptLineInventory] which will do a lookup in the Cross-Reference table.

The INTran table.inventoryID field is decorated with [StockItem] which doesn’t do a cross-reference lookup.

Creating a field and giving it [CrossItem] will do a cross-reference lookup.

I know that CrossItem and StockItem cannot be added at the same time. 

Is there an existing attribute that would allow me to replace the StockItem attribute on a field in a customization that would add cross-reference lookups like CrossItem allows for?

icon

Best answer by Gabriel Michaud 6 April 2021, 22:29

View original

4 replies

Userlevel 7
Badge +5

Right on!  Thanks for digging into that!

Userlevel 7
Badge +10

I did some troubleshooting and found the issue -- the CrossItem attribute doesn’t work with the default constructor; I think this is simply because there are no places in Acumatica where it is used this way.

Even though you don’t have a customer or vendor field in Inventory Tranfers, I managed to get it to work this way: 

    [CrossItem(INPrimaryAlternateType.CPN, Filterable = true, BqlField = typeof(INTran.inventoryID))]
protected virtual void INTran_InventoryID_CacheAttached(PXCache cache)
{
}

 

Userlevel 7
Badge +5

Thank you for your reply - I appreciate you digging into that.

I had tried adjusting the attributes via a Graph Extension but entering the barcode or global cross-reference returned an error.

  public class INTransferEntry_Extension : PXGraphExtension<INTransferEntry>

  {

    #region Event Handlers

    //[PXDefault()]

    //[StockItem(DisplayName="Inventory ID")]

    //[PXForeignReference(typeof(FK.InventoryItem))]

    [CrossItem]

    protected virtual void INTran_InventoryID_CacheAttached(PXCache cache)

    {

    

    }

    #endregion

  }

 

So maybe there’s something else going on within the Transfer logic that I need to dig through more because I get an on-screen error:

“Error: An error occurred during processing of the field InventoryID: Value cannot be null. Parameter name: key.”

The error trace starts with:

”The item InventoryID is not found (restricted:False,external:True,value:THATLEGOPT)“

Then:
“Value cannot be null.
Parameter name: key
   at PX.Data.PXCache`1.FillWithValues(TNode item, TNode copy, IDictionary values, PXCacheOperation operation, Boolean externalCall)“
 
And finally, the error that is shown on the screen (listed above).
 
 
Userlevel 7
Badge +10

Why not simply use [CrossItem] ? The POReceiptLineInventory attribute simply inherits from CrossItem and adds a filter to prevent you from selecting items that have status set to No Purchases. CrossItemAttribute itself inherits from the same base class as StockItemsAttribute  - you don’t need to use StockItem as well.

 

    [PXDBInt()]
[PXUIField(DisplayName = "Inventory ID", Visibility = PXUIVisibility.Visible)]
public class POReceiptLineInventoryAttribute : CrossItemAttribute
{
public POReceiptLineInventoryAttribute(Type receiptType)
: base(typeof(Search<InventoryItem.inventoryID, Where<Match<Current<AccessInfo.userName>>>>), typeof(InventoryItem.inventoryCD), typeof(InventoryItem.descr), INPrimaryAlternateType.VPN)
{
var condition = BqlTemplate.OfCondition<
Where<Current2<BqlPlaceholder.A>, Equal<POReceiptType.transferreceipt>,
Or<InventoryItem.itemStatus, NotEqual<InventoryItemStatus.noPurchases>>>>
.Replace<BqlPlaceholder.A>(receiptType)
.ToType();

_Attributes.Add(new PXRestrictorAttribute(condition, IN.Messages.ItemCannotPurchase));
}
}

 

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