Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

acumatica - How to make sure specific line from PXSelector is chosen

I've got a PXSelector that selects several fields, the first one being a field whose value may be repeated (as follows):

Field1       Field2       Field3   
1234         LL           description1
1234         PS           description2
1234         CC           description3
4321         BB           description4

PXSelector code:

  [PXSelector(typeof(myTable.field1)
               ,typeof(myTable.field1)
               ,typeof(myTable.field2)
               ,typeof(myTable.field3)
               ,DescriptionField = typeof(myTable.field3))]

The DAC for the selected table has Field1 and Field2 as keys.

If I select row two or three above, I'll get the row one's Field3 description every time. Is there a way to ensure that I only get the description of the row that I've selected, instead of always getting the first occurrence?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have to make the selector operate on a single key because the selected value is the key field not the whole DAC record.

One possible approach is to add a unique record number column to the database table, make the selector operate on that column and set a different 'TextField' property for the selector so it doesn't show the record number.

Here's how I did it to make a selector on SerialNumber/InventoryItem which is not a unique value (contains duplicate).

Database scripts will vary with database systems. I'm using this script for MSSQL to add the unique record number to the table:

--[mysql: Skip]  
--[IfNotExists(Column = SOShipLineSplit.UsrUniqueID)]
BEGIN
    alter table SOShipLineSplit add UsrUniqueID int identity(1,1)
END
GO

This is the DAC declaration. I use PXDBIdentity to match the DB identity field type that tag the column as a record number field:

[Serializable]
public class SOShipLineSplit_Extension : PXCacheExtension<SOShipLineSplit>
{
    #region UsrUniqueID
    public abstract class usrUniqueID : IBqlField { }

    [PXDBIdentity(IsKey = false)]
    [PXUIField(DisplayName = "ID")]
    public virtual int? UsrUniqueID { get; set; }
    #endregion
}

I use another DAC field for the selector which uses this unique id key and I set the description to the real field I want to appear in the selector:

#region SerialUniqueID
public abstract class serialUniqueID : IBqlField { }

[PXSelector(typeof(Search5<SOShipLineSplit_Extension.usrUniqueID,
                    InnerJoin<SOShipment, On<SOShipment.customerID, Equal<Current<customerID>>,
                                          And<SOShipment.shipmentNbr, Equal<SOShipLineSplit.shipmentNbr>>>,
                    InnerJoin<InventoryItem, On<InventoryItem.inventoryID, Equal<SOShipLineSplit.inventoryID>>>>,
                    Where<SOShipLineSplit.lotSerialNbr, NotEqual<StringEmpty>>,
                    Aggregate<GroupBy<SOShipLineSplit.lotSerialNbr,
                              GroupBy<SOShipLineSplit.inventoryID>>>>),
            typeof(SOShipLineSplit.lotSerialNbr),,
            typeof(SOShipLineSplit.inventoryID),
            typeof(InventoryItem.descr),
            CacheGlobal = true,
            DescriptionField = typeof(SOShipLineSplit.lotSerialNbr))]
[PXDBInt]
[PXUIField(DisplayName = "Serial Number")]
public virtual int? SerialUniqueID { get; set; }
#endregion

For this selector I want to display LotSerialNbr in the textbox instead of the unique id. Because the selector displays it's key by default I need to use the TextField property:

<px:PXSelector ID="edSerialUniqueID" 
               runat="server" 
               DataField="SerialUniqueID"
               TextField="LotSerialNbr" 
               AutoGenerateColumns="True">

The selector value will contain the selected unique id field. To get the record you can issue another request to the database using that key.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...