Skip to main content
Answer

Filter Material Wizard 1 Screen (AM300010) by User Defined Warehouse Selector

  • November 22, 2024
  • 4 replies
  • 67 views

Forum|alt.badge.img+2

Hi I have added a user defined warehouse selector as below in the Material Wizard 1 screen in Acumatica.

[PXInt]
[PXSelector(
typeof(Search<INSite.siteID>),
typeof(INSite.siteCD),
typeof(INSite.descr),
SubstituteKey = typeof(INSite.siteCD))]
[PXUIField(DisplayName="Warehouse")]

The records should be filtered based on the selected warehouse, but no filtering occurs. I have implemented the filtering logic below.

using System;
using PX.Data;
using System.Collections.Generic;
using PX.Objects.CS;
using System.Collections;
using System.Linq;
using PX.Objects.IN;
using PX.Objects.AM.Attributes;
using PX.Objects;
using PX.Objects.AM;

namespace PX.Objects.AM
{
public class MatlWizard1_Extension : PXGraphExtension<PX.Objects.AM.MatlWizard1>
{

#region View Extensions
public override void Initialize()
{
base.Initialize();

// Modify the existing processing delegate
Base.OpenOrders.SetProcessDelegate(list =>
{
var filter = Base.filter.Current;
if (filter != null)
{
var warehouseFilter = filter.GetExtension<WizFilterExt>();
if (warehouseFilter?.UsrWarehouseSelector2 != null)
{
// Convert string to int for comparison
var warehouseID = int.Parse(warehouseFilter.UsrWarehouseSelector);
// Filter the list by warehouse before processing
list = list.Where(item => item.SiteID == warehouseID).ToList();
}
}

// Call the original FillMatlWrk method
MatlWizard1.FillMatlWrk(list, filter);
});
}

// Add view delegate to modify the select command
protected virtual IEnumerable openOrders()
{
var baseView = new PXView(Base, true,
Base.OpenOrders.View.BqlSelect);

var startRow = PXView.StartRow;
int totalRows = 0;

var filter = Base.filter.Current;
if (filter == null)
{
return baseView.Select(PXView.Currents, PXView.Parameters,
PXView.Searches, PXView.SortColumns, PXView.Descendings,
PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows);
}

var warehouseFilter = filter.GetExtension<WizFilterExt>();
if (warehouseFilter?.UsrWarehouseSelector2 == null)
{
return baseView.Select(PXView.Currents, PXView.Parameters,
PXView.Searches, PXView.SortColumns, PXView.Descendings,
PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows);
}

// Add warehouse filter
var warehouseID = warehouseFilter.UsrWarehouseSelector2.Value;
var select = new PXSelect<AMProdItem,
Where<AMProdItem.function, NotEqual<OrderTypeFunction.disassemble>,
And<Where<AMProdItem.isOpen, Equal<True>,
And<AMProdItem.completed, NotEqual<True>,
And<AMProdItem.siteID, Equal<Required<AMProdItem.siteID>>>>>>>>(Base);

return select.Select(warehouseID);
}
#endregion
}
}

Please let me know how I can get this working, thank you!

Best answer by TharidhiP

Hi ​@Dipak Nilkanth and ​@noorula77 thanks a lot for your suggestions! I went through my code base and set the Commit Changes property of the user defined selector to true and the filtering occurred as expected.

4 replies

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

Hi ​@TharidhiP,

I believe you need to add a filter view to your header DAC.
Then, match the WarehouseID from both the header and detail DACs using a BQL query in a separate view. Use this view to display records based on the parameter in the header filter DAC.

Below is the code to help you understand the logic. Update the DAC names and fields as per your requirements:

public PXFilter<HeaderFilterDAC> Filter;

[PXFilterable]
public PXSelectJoinOrderBy<
DetailDAC,
LeftJoin<HeaderFilterDAC,
On<DetailDAC.warehouseID, Equal<HeaderFilterDAC.warehouseID>>>,
OrderBy<Desc<DetailDAC.docDate>>> Result;

Hope, it helps!


Forum|alt.badge.img+1
  • Jr Varsity III
  • November 22, 2024

Hi ​@TharidhiP ,
In the field editor for this selector access layout properties and set the FilterByAllFields property to True. .


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

Hi ​@noorula77,

I believe, ​@TharidhiP wants to filter warehouse ID from warehouse field from Options section which is in header, FilterByAllFields will apply on the grid selector columns and it will filter the selector columns only.


Forum|alt.badge.img+2
  • Author
  • Pro III
  • Answer
  • November 25, 2024

Hi ​@Dipak Nilkanth and ​@noorula77 thanks a lot for your suggestions! I went through my code base and set the Commit Changes property of the user defined selector to true and the filtering occurred as expected.