Skip to main content
Answer

How perform .Search on PrimaryView

  • June 4, 2024
  • 2 replies
  • 71 views

aaghaei
Captain II
Forum|alt.badge.img+10

Hello All,

 

I am in need to make a piece of code generic to dynamically find and search in the Graph’s PrimaryView. If I am to strongly type my graph type and then perform search it just works file. for example

graph.Document.Current = graph.Document.Search<APInvoice.noteID>(refNoteID);

but if I want to make it generic so the platform searches in my PrimaryView then .Search is not recognized. This is what I am doing

graph.Views[graph.PrimaryView].Cache.Current = graph.Views[graph.PrimaryView].Search<NoteField>(refNoteID);

Any idea how to convert my static search method to a dynamic version that searches in the PrimaryView of the graph?

Best answer by NicholasBova52

Hello @aaghaei 

Looks like it will require some additional complexity to get Search working generically, since the Search method is only available in PXSelectBase and not in the PXView that you’re getting from graph.Views[graph.PrimaryView]. If you wanted to get Search working on PXView for any arbitrary field, then you would likely need to replace the Where clause of the PXView and then perform Select on the view, making sure to supply the currents, searches, sort fields, and the other parameters that PXView.Select requires.

 

Do you only need to search for records based on the RefNoteID? If so, the easiest way to do this would be to use the EntityHelper. You can create an instance of the EntityHelper, then use GetEntityRow to search for the record you need.

var helper = new EntityHelper(graph);
var row = helper.GetEntityRow(refNoteID);
Base.Views[Base.PrimaryView].Cache.Current = row;

If needed, you can perform type checking on the object that the EntityHelper returns to ensure that it is of the same type of the records used by the cache in the primary view.

 

if (Base.Views[Base.PrimaryView].Cache.GetItemType() == row.GetType()) 
{
Base.Views[Base.PrimaryView].Cache.Current = row;
}

 

2 replies

NicholasBova52
Acumatica Employee
Forum|alt.badge.img+1
  • Acumatica Employee
  • Answer
  • June 6, 2024

Hello @aaghaei 

Looks like it will require some additional complexity to get Search working generically, since the Search method is only available in PXSelectBase and not in the PXView that you’re getting from graph.Views[graph.PrimaryView]. If you wanted to get Search working on PXView for any arbitrary field, then you would likely need to replace the Where clause of the PXView and then perform Select on the view, making sure to supply the currents, searches, sort fields, and the other parameters that PXView.Select requires.

 

Do you only need to search for records based on the RefNoteID? If so, the easiest way to do this would be to use the EntityHelper. You can create an instance of the EntityHelper, then use GetEntityRow to search for the record you need.

var helper = new EntityHelper(graph);
var row = helper.GetEntityRow(refNoteID);
Base.Views[Base.PrimaryView].Cache.Current = row;

If needed, you can perform type checking on the object that the EntityHelper returns to ensure that it is of the same type of the records used by the cache in the primary view.

 

if (Base.Views[Base.PrimaryView].Cache.GetItemType() == row.GetType()) 
{
Base.Views[Base.PrimaryView].Cache.Current = row;
}

 


aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • June 7, 2024

@NicholasBova52 Thank you very much for the tip. It does the trick.