0
votes

I have a field at in the filter section of a processing page that does not impact the selection of the rows, but determines how the rows are processed. I created a public variable and set it on the filter row selected event, but it seems to get reset when the Graph is called again to process the rows. Clicking Process does not cause the row selected method to fire. I have been looking for a way to access the filter cache during the process method but I have been unsuccessful. How can I either save this value or access the filter cache from the processing method?

1

1 Answers

1
votes

You have to capture the filter value in the delegate closure. This is the pattern I use to do that:

PXFilter<ProcessFilter> filter;

public void ProcessFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
   ProcessFilter filter = e.Row as ProcessFilter;

   if (filter != null)
   {
       DataView.SetProcessDelegate(delegate (List<DAC> dacRecords) 
       { 
           ExecuteProcess(filter, dacRecords); 
       });
   }
}

public static void ExecuteProcess(ProcessFilter filter, List<DAC> dacRecords)
{
   // filter should contain the value captured at closure 
   // when calling SetProcessDelegate

   // You have to create a new graph to process the DAC Records 
   YourGraph newGraph = PXGraph.CreateInstance<YourGraph>();

   foreach (DAC dacRecord in dacRecords)
   {
      // Use newGraph to modify the records
   }

   // Save newGraph to persist the changes
}