How to work with selector

Hello everybody,

today I want to write few words how to work with selectors in Acumatica.

So, imagine, you have the following selector in Acumatica:

<px:PXSelector ID="NmbUsrBillPMTask" runat="server" DataField="UsrBillPMTask"/>

In order to make it work as selector, you need to do the following:

[PXSelector(typeof(Search<PMTask.taskID>))]

if you'll do it, you'll receive following selector:

And if you choose there some value, you'll be able to see id represented as number. In my case it was 727.

But what if you want to make it more readable?

Then you can add following part:

[PXSelector(typeof(Search<PMTask.taskID>), SubstituteKey = typeof(PMTask.taskCD))]

Then instead of some strange number Acumatica will display TaskCD field. 

But what if you have desire to add as display one more field displayed after "-" sign, as it is in some Acumatica screens. You can add another element, which is named DescriptionField. 

And final part of advice, you can also customize which fields should go in the selector. Take see at the following code:

[PXSelector(typeof(Search<PMTask.taskID,
            Where<PMTask.projectID, Equal<Current<PMTask.projectID>>>>), new Type[]{typeof (PMTask.taskCD), typeof (PMTask.locationID),
                typeof (PMTask.description), typeof (PMTask.status)}, SubstituteKey = typeof(PMTask.taskCD), DescriptionField = typeof(PMTask.description))]

You can try to figure out details at screenshot:

Hope that can help somebody to create selector.

9 Comments

  • dedi said

    Hello

    I made code like this

    [PXDBString(5)]
    [PXUIField(DisplayName="Case No")]
    [PXSelector(typeof(Search<ShipmentSKR.SOShipLineCaseNoSKR.CaseNbr>))]



    I created this code for custom field in shipment tab packages, ShipmentSKR.SOShipLineCaseNoSKR.CaseNbr Is a custom table, But when publish, there is an error likes this

    IIS APPPOOL\SKRDevTest
    Building directory '\WebSiteValidationDomain\App_RuntimeCode\'.
    \App_RuntimeCode\PX_Objects_SO_SOPackageDetail_extensions.cs(19): error CS0118: 'ShipmentSKR.SOShipLineCaseNoSKR.CaseNbr' is a 'property' but is used like a 'type'
    \App_RuntimeCode\PX_Objects_SO_SOPackageDetail_extensions.cs(19): error CS0118: 'ShipmentSKR.SOShipLineCaseNoSKR.CaseNbr' is a 'property' but is used like a 'type'
    Compiler time, in seconds: 7,510337

    Please Help Me, thank you

  • docotor said

    Hello Dedi. Your problem is not with code, but with MS SQL configuration. Your code is correct. You need to add user SKRDevTest as authorized at your SQL server

  • Dave said

    Hi, I am getting a similar error to the above and wondering if you can help?

    I added a field to the customer master to link a business account as a "reseller". Below is my code:

    [PXUIField(DisplayName="Reseller",Visibility = PXUIVisibility.SelectorVisible)]
    [PXSelector(typeof(Search<BAccountR.bAccountID>),
    DescriptionField = typeof(BAccountR.AcctName),
    SubstituteKey = typeof(BAccountR.bAccountID))]

    I'm getting the below...

    Error:
    IIS APPPOOL\DefaultAppPool
    Building directory '\WebSiteValidationDomain\App_RuntimeCode\'.
    \App_RuntimeCode\PX_Objects_CR_BAccount_extensions.cs(26): error CS0118: 'PX.Objects.CR.BAccount.AcctName' is a 'property' but is used like a 'type'
    \App_RuntimeCode\PX_Objects_CR_BAccount_extensions.cs(26): error CS0118: 'PX.Objects.CR.BAccount.AcctName' is a 'property' but is used like a 'type'
    Compiler time, in seconds: 4.7926131

    But if I change BAccountR.AcctName to BAccount.bAccountID it works but on my screen it just shows the ID twice.

    Thanks!

  • docotor said

    Your questions shows that you need some improvement in code conventions used by Acumatica. Each column is reflected by two lines: capital letter of column name and small of column name. Instead of BAccountR.AcctName try to use BAccountR.acctName and error will go away.

  • Royce Lithgo said

    It looks like inclusion of the SubstituteKey = parameter makes the "Search<>" component redundant because the selected value will be whatever is nominated for the SubstiuteKey. Why is it then in your code and also the Framework training courses Select<> (on the primary key) is still specified even though the value returned will be the natural key (specified by SubstituteKey)?

    Here's an example - these 2 code segments produce exactly the same result:

    [PXSelector(
    typeof(Search<Customer.customerID>),
    typeof(Customer.customerCD),
    typeof(Customer.companyName),
    SubstituteKey = typeof(Customer.customerCD))]

    [PXSelector(
    typeof(Customer.customerID),
    typeof(Customer.customerCD),
    typeof(Customer.companyName),
    SubstituteKey = typeof(Customer.customerCD))]

    This however doesn't work (selector wont launch)
    [PXSelector(
    typeof(<Customer.customerID>,
    typeof(Customer.customerCD),
    typeof(Customer.companyName))]

    This works, but returns primary (numeric) key:
    [PXSelector(
    typeof(Search<Customer.customerID>),
    typeof(Customer.customerCD),
    typeof(Customer.companyName))]

  • docotor said

    I can't say about reasons of Acumatica manuals, but mine reason is that Search allows to add some kind of filtering with Where<> . Without Search add Where condition will be problematic

  • Prat said

    How do we use required<> in place of current<> and pass some string constant for selector?

  • docotor said

    Pratt, I'll create new article that explains this

  • docotor said

    Hi Pratt, please take a look: Hello Pratt, take a look: https://blog.zaletskyy.com/required-instead-of-current-in-acumatica

Add a Comment