Skip to main content
Answer

Enable Filtering and Sorting for Unbound Custom Fields in Grid (AR402000)

  • November 30, 2024
  • 11 replies
  • 227 views

DipakNilkanth
Pro III
Forum|alt.badge.img+13

Hi Experts,

I have a requirement from a client regarding custom fields on the Customer Details (AR402000) screen. Specifically, the client wants the ability to filter and sort unbound custom fields directly in the grid.

Here is the scenario:

  • I added two unbound custom fields, Location ID and Location Name (both string data types), to the grid.
  • The client wants to:
    1. Filter records in the grid by typing a value in these custom fields.
    2. Sort the records in ascending or descending order based on these fields.

What I've Tried So Far:

  1. Added the custom fields (UsrLocationID and UsrLocationName) to the FastFilterFields property (along with fields like RefNbr, ExtRefNbr, and DocDesc).
  2. Set the AllowFilter and AllowSort properties to true for these fields in the customization editor.

However, the filtering and sorting functionality is still not working for these unbound fields.

Question:

Is it possible to enable filtering and sorting for unbound custom fields using Acumatica's built-in attributes or customization editor? Or do we need to write custom logic to achieve this?

If custom logic is required, could you please provide guidance or an example of how to implement it?

Thank you in advance for your help!

Best answer by noorula77

Hi ​@Dipak Nilkanth ,
  Try below code using fieldselecting event hope it will work.

 

 protected void ARDocumentResult_Usrlocation_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
 {

     var row = (ARDocumentResult)e.Row;
     if (row == null) return;
    

     string locationID = "";

     ARRegister aRRegister = PXSelect<PX.Objects.AR.ARRegister,
         Where<ARRegister.refNbr, Equal<Required<ARRegister.refNbr>>,
         And<ARRegister.docType, Equal<Required<ARRegister.docType>>>>>
         .Select(Base, row.RefNbr, row.DocType);

     if (aRRegister?.CustomerLocationID != null)
     {
         Location location = PXSelect<Location,
             Where<Location.locationID, Equal<Required<Location.locationID>>>>
             .Select(Base, aRRegister.CustomerLocationID);

         if (location?.LocationCD != null)
         {
             locationID = location.LocationCD.Trim();
         }
     }

     e.ReturnValue = locationID;

 }
 

11 replies

darylbowman
Captain II
Forum|alt.badge.img+15

How are you populating the unbound fields?


DipakNilkanth
Pro III
Forum|alt.badge.img+13
  • Author
  • Pro III
  • November 30, 2024

Hi ​@darylbowman,

Thanks for the prompt response.

I am populating fields from Comission Settings tab of Invoices and Memos screen.

I am fetching it by comparing invoice RefNbr of grid row to invoices and Memos screen and retrieving record from SalesPersonARTran DAC by BQL query.

 


darylbowman
Captain II
Forum|alt.badge.img+15

I meant what event handler are you using?


DipakNilkanth
Pro III
Forum|alt.badge.img+13
  • Author
  • Pro III
  • November 30, 2024

Hi ​@darylbowman,

I am using RowSelected event of ARDocumentResult graph as below to fetch the Location.

 protected void ARDocumentResult_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
        {

            var row = (ARDocumentResult)e.Row;
            //If the row is null, return
            if (row == null) return;
            //If the customer ID is not null
            if (row.RefNbr != null && (row.DocType == "INV" || row.DocType == "CRM"))
            {
                ARDocumentResultExt resultExt = row.GetExtension<ARDocumentResultExt>();


               resultExt.UsrLocationID = GetLocationID(row.RefNbr, row.DocType);
                resultExt.UsrLocation = GetLocationName(row.RefNbr, row.DocType);


            }
        }



My mistake in previous Comment, I am fetching location as below.
 

private string GetLocationID(string refNbr, string docType)
{
LocationID = "";
ARRegister aRRegister = PXSelect<ARRegister, Where<ARRegister.refNbr, Equal<Required<ARRegister.refNbr>>, And<ARRegister.docType, Equal<Required<ARRegister.docType>>>>>.Select(this.Base, refNbr, docType);
if (aRRegister != null)
{
if (aRRegister.CustomerLocationID != null)
{
Location location = PXSelect<Location, Where<Location.locationID, Equal<Required<Location.locationID>>>>.Select(this.Base, aRRegister.CustomerLocationID);
if (location != null)
{
LocationID = location.LocationCD.Trim();
}
}
}
return LocationID;
}

 


darylbowman
Captain II
Forum|alt.badge.img+15

I'm not saying this is THE problem, but using RowSelected for this sort of thing is highly discouraged.

If the rows are actually being selected from the database, RowSelectING would probably be a better option.

I'm not aware of any limitations of unbound fields when it comes to sorting and filtering.


DipakNilkanth
Pro III
Forum|alt.badge.img+13
  • Author
  • Pro III
  • December 2, 2024

@darylbowman ,

Yes, I aware that using the RowSelected event for such purposes is not recommended. However, the code was initially written by another developer, and we've recently received a requirement to add filtering to these custom fields.

Thank you for your insights on this; I truly appreciate your time and assistance.
Is there anyone have some thoughts to share on limitations of unbound fields when it comes to sorting and filtering.
 


Forum|alt.badge.img+1
  • Jr Varsity III
  • December 2, 2024

Hi ​@Dipak Nilkanth ,
      On unbound field instead of Rowselected event try with PXDBScalar.


DipakNilkanth
Pro III
Forum|alt.badge.img+13
  • Author
  • Pro III
  • December 3, 2024

Hi ​@noorula77, As I know, PXDBScaler attribute used to define a calculated field. The Custom fields I have those are Text fields populating Location ID and Description.
Thanks!


Forum|alt.badge.img+1
  • Jr Varsity III
  • December 3, 2024

Hi ​@Dipak Nilkanth ,
  You can display text field data also using PXDBScaler.


Forum|alt.badge.img+1
  • Jr Varsity III
  • Answer
  • December 4, 2024

Hi ​@Dipak Nilkanth ,
  Try below code using fieldselecting event hope it will work.

 

 protected void ARDocumentResult_Usrlocation_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
 {

     var row = (ARDocumentResult)e.Row;
     if (row == null) return;
    

     string locationID = "";

     ARRegister aRRegister = PXSelect<PX.Objects.AR.ARRegister,
         Where<ARRegister.refNbr, Equal<Required<ARRegister.refNbr>>,
         And<ARRegister.docType, Equal<Required<ARRegister.docType>>>>>
         .Select(Base, row.RefNbr, row.DocType);

     if (aRRegister?.CustomerLocationID != null)
     {
         Location location = PXSelect<Location,
             Where<Location.locationID, Equal<Required<Location.locationID>>>>
             .Select(Base, aRRegister.CustomerLocationID);

         if (location?.LocationCD != null)
         {
             locationID = location.LocationCD.Trim();
         }
     }

     e.ReturnValue = locationID;

 }
 


DipakNilkanth
Pro III
Forum|alt.badge.img+13
  • Author
  • Pro III
  • December 4, 2024

Hi ​@noorula77,

Thank you for the code snippet. It worked for me. 

Appreciate your help on this.