Bikash Lama
Bikash Lama

Reputation: 186

Populate InventoryID while searching for cross reference alternate ID

I have been trying to select inventory using 'UsrAlternateIDs' (custom field) value (which are concatenation of cross reference value of stock items). This is where I am trying to implement. enter image description here

So, if I type in correct InventoryID, it would select me the inventory which exists now. But now, whatever value I type, first it would check if it is the correct inventoryID and select inventory for me. if not it should look for alternateids of inventory item and if I type whichever (separated from ';') it should select inventory item for me.

Here is the code snippet I have written:

protected void FSAppointmentDetPart_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
      
      var row = (FSAppointmentDetPart)e.Row;
      if(row==null) return;
      InventoryItem item = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<row.InventoryID>>;
      if(item!=null)
      {
         InventoryItem itm = PXSelect<Inventory, Whenre<InventoryItem.alternateIDs, Contains<row.InventoryID>>;
         if(itm!=null)
         {
           
         }
         else
         {
           throw new PXException("Invalid Inventory Item");
          }
      }
      //sender.SetValue<ContactExt.usrCreditRecordVerified>(e.Row, false);
}

But it is not working. What I am I missing?

Besides, I also looked into the Business logic of the page 'Purchase Orders' which would look for column AlternateIDs and work if is not concatenated and only single value. But the code doesn't make much sense to me. It would be great if you could explain that to me.

Thank you.

Upvotes: 0

Views: 530

Answers (1)

Sin
Sin

Reputation: 1864

If you are trying to make your selector search for both inventory id and the alternate id, consider using the

CrossItemAttribute

Sample usage can be like this, here INPrimaryAlternateType.CPN defines the type of alternate id.

#region InventoryID
            public abstract class inventoryID : PX.Data.IBqlField
            {
            }
            protected Int32? _InventoryID;
            [CrossItem(INPrimaryAlternateType.CPN, Filterable = true)]
            public virtual Int32? InventoryID
            {
                get
                {
                    return this._InventoryID;
                }
                set
                {
                    this._InventoryID = value;
                }
            }
            #endregion

EDIT

Tried to use as an unbound field

        #region InvID
        public abstract class invID : PX.Data.IBqlField { }
        [PXInt]        
        [CrossItem(DisplayName="TEST")]
        public virtual int? InvID { get; set; }
        #endregion InvID

Item master info enter image description here

Unbound field, Keys in the barcode

enter image description here

System Finds the correct Item

enter image description here

Upvotes: 2

Related Questions