Skip to main content
Solved

How perform .Search on PrimaryView

  • 4 June 2024
  • 2 replies
  • 43 views

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.Viewsegraph.PrimaryView].Cache.Current = graph.Viewsegraph.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?

2 replies

Userlevel 4
Badge +1

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;
}

 

Userlevel 7
Badge +9

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

Reply