2
votes

I created a selector control which displays a list of all serial #s from INItemLotSerial table, it works fine, the problem is the description field is showing InventoryID, how to show InventoryCD. Please have a look at below sample code.

[PXSelector(typeof(Search<INItemLotSerial.lotSerialNbr>),
    new Type[] { typeof(INItemLotSerial.lotSerialNbr), typeof(INItemLotSerial.inventoryID) },
    SubstituteKey = typeof(INItemLotSerial.lotSerialNbr), DescriptionField = typeof(INItemLotSerial.inventoryID))]

// i also joined with InventoryItem but this doesn't works.

[PXSelector(typeof(Search2<INItemLotSerial.lotSerialNbr,
        LeftJoinSingleTable<InventoryItem, On<InventoryItem.inventoryID,Equal<INItemLotSerial.inventoryID>>>>),
    new Type[] { typeof(INItemLotSerial.lotSerialNbr), typeof(INItemLotSerial.inventoryID) },
    SubstituteKey = typeof(INItemLotSerial.lotSerialNbr), DescriptionField = typeof(InventoryItem.inventoryCD))]

enter image description here

1

1 Answers

2
votes

The main problem with DescriptionField property is that it is waiting for getting the field from the same table for which Selector is written. But in the case of ID/CD usually, the CD is not present in the table where ID is present, except the main table.

UPDATED I have removed previous code (implementation using custom attributes and FieldSelecting event handler) because of the performance issues which it is bringing with it. The code below is resulting with the same lookup but getting the data with one inner join instead of all the requests which the previous code was doing.

You can do the following to get this lookup with description:

  1. Create a PXProjection on INItemLotSerial and InventoryItem tables like below:

    [PXCacheName("Lot Serials with Inventory CD")]
    [PXProjection(typeof(Select2<INItemLotSerial,
        InnerJoin<InventoryItem,
                On<INItemLotSerial.inventoryID, Equal<InventoryItem.inventoryID>>>>))]
    public class INItemLotSerialWithInventoryItem : IBqlTable
    {
        [PXDBInt(BqlField = typeof(INItemLotSerial.inventoryID))]
        [PXUIField(DisplayName = "Inventory ID", Visibility = PXUIVisibility.Visible, Visible = false)]
        public virtual int? InventoryID { get; set; }
    
        public abstract class inventoryID : IBqlField { }
    
        [PXDBString(InputMask = "", IsUnicode = true, BqlField = typeof(InventoryItem.inventoryCD))]
        [PXUIField(DisplayName = "Inventory ID")]
        public virtual string InventoryCD { get; set; }
        public abstract class inventoryCD : IBqlField { }
    
        [PXDBString(InputMask = "", IsUnicode = true, BqlField = typeof(INItemLotSerial.lotSerialNbr))]
        [PXUIField(DisplayName = "Lot/Serial Nbr")]
        public virtual string LotSerialNbr { get; set; }
        public abstract class lotSerialNbr : IBqlField { }
    }
    
  2. Set your selector to use this PXProjection like below:

    [PXSelector(typeof(Search<INItemLotSerialWithInventoryItem.lotSerialNbr>),
    new Type[] { typeof(INItemLotSerialWithInventoryItem.lotSerialNbr) }, 
        SubstituteKey = typeof(INItemLotSerialWithInventoryItem.lotSerialNbr), 
        DescriptionField = typeof(INItemLotSerialWithInventoryItem.inventoryCD))]
    

As a result, you will get lookup like below: enter image description here