Skip to main content
Solved

Is there an attribute that merges StockItem with CrossItem?


Forum|alt.badge.img+6

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?

Best answer by Gabriel Michaud

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

 

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

4 replies

Gabriel Michaud
Captain II
Forum|alt.badge.img+11

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

 


Forum|alt.badge.img+6
  • Author
  • Captain II
  • 556 replies
  • April 6, 2021

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).
 
 

Gabriel Michaud
Captain II
Forum|alt.badge.img+11

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

 


Forum|alt.badge.img+6
  • Author
  • Captain II
  • 556 replies
  • April 6, 2021

Right on!  Thanks for digging into that!


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