带有 Search BQL 的 PXSelector 防止记录删除
PXSelector with Search BQL prevents record deletion
我有 ProductLine 和 ProductLineItem DAC。产品线包含相关库存项目的集合。
public class ProductLine : IBqlTable
{
[PXDBIdentity()]
public virtual int? LineID { get; set; }
public abstract class lineID : IBqlField { }
[PXDBString(50, IsKey = true)]
[PXUIField(DisplayName = "Line ID")]
[PXDefault]
[PXSelector(typeof(ProductLine.lineCD),
typeof(ProductLine.lineCD),
typeof(ProductLine.description))]
public virtual string LineCD { get; set; }
public abstract class lineCD : IBqlField { }
// ...
}
public class ProductLineItem : IBqlTable
{
[PXDBInt(IsKey = true)]
[PXDBDefault(typeof(ProductLine.lineID))]
[PXParent(typeof(Select<ProductLine,
Where<ProductLine.lineID,
Equal<Current<ProductLineItem.lineID>>>>))]
public virtual int? LineID { get; set; }
public abstract class lineID : IBqlField { }
[PXDBInt(IsKey = true)]
[PXUIField(DisplayName = "Inventory ID")]
[PXSelector(
typeof(Search2<InventoryItem.inventoryID,
LeftJoin<ProductLineItem,
On<ProductLineItem.lineID, Equal<Current<ProductLineItem.lineID>>,
And<ProductLineItem.inventoryID, Equal<InventoryItem.inventoryID>>>>,
Where<InventoryItem.itemStatus, Equal<InventoryItemStatus.active>,
And<ProductLineItem.lineID, IsNull>>>),
new Type[] {
typeof(InventoryItem.inventoryCD),
typeof(InventoryItem.descr)
},
SubstituteKey = typeof(InventoryItem.inventoryCD))]
public virtual int? InventoryID { get; set; }
public abstract class inventoryID : IBqlField { }
// ...
}
然后在一个非常简单的 FormDetail 入口页面中实现这些。
public class ProductLineEntry : PXGraph<ProductLineEntry, ProductLine>
{
public PXSelect<ProductLine> ProductLines;
public PXSelect<ProductLineItem,
Where<ProductLineItem.lineID,
Equal<Current<ProductLine.lineID>>>> ProductLineItems;
}
ProductLineItem.inventoryID 上的 PXSelector 提供尚未添加到当前产品线的活动项目。 However, when the Selector is written like this attempting to Delete an item from the grid results in the red "x" indicator appearing but the record is never actually removed.
将 PXSelector 更改为更基本的没有 Search2<>...
[PXSelector(typeof(InventoryItem.inventoryID),
typeof(InventoryItem.inventoryCD),
typeof(InventoryItem.descr),
SubstituteKey = typeof(InventoryItem.inventoryCD))]
...记录正常删除
如何在选择器中使用搜索<> BQL 并且仍然能够从详细信息网格中删除记录?
问题的发生是因为 ProductLineItem.InventoryID 字段是关键字段,并且为此字段定义的 BQL 搜索未 returning InventoryItem 为您尝试删除的 ProductLineItem 记录选择。
框架作为 Delete 操作的一部分所做的第一件事是调用 FieldUpdating 和 FieldUpdated 所有已删除记录键字段的处理程序。在您的情况下,这些处理程序由于 PXSelectorAttribute 无法找到为删除的 ProductLineItem[=30= 选择的 InventoryItem 而失败] 记录。有关详细信息,请参阅 Acumatica API Reference。
解决此问题的最简单方法是将 ProductLineItem.InventoryID 字段上的 BQL 搜索修改为 return 两个尚未添加到的活动项目当前产品线和为当前 ProductLineItem 记录选择的项目:
Where2<Where<InventoryItem.itemStatus, Equal<InventoryItemStatus.active>,
And<ProductLineItem.lineID, IsNull>>>,
Or<InventoryItem.inventoryID, Equal<Current<ProductLineItem.inventoryID>>>>
我有 ProductLine 和 ProductLineItem DAC。产品线包含相关库存项目的集合。
public class ProductLine : IBqlTable
{
[PXDBIdentity()]
public virtual int? LineID { get; set; }
public abstract class lineID : IBqlField { }
[PXDBString(50, IsKey = true)]
[PXUIField(DisplayName = "Line ID")]
[PXDefault]
[PXSelector(typeof(ProductLine.lineCD),
typeof(ProductLine.lineCD),
typeof(ProductLine.description))]
public virtual string LineCD { get; set; }
public abstract class lineCD : IBqlField { }
// ...
}
public class ProductLineItem : IBqlTable
{
[PXDBInt(IsKey = true)]
[PXDBDefault(typeof(ProductLine.lineID))]
[PXParent(typeof(Select<ProductLine,
Where<ProductLine.lineID,
Equal<Current<ProductLineItem.lineID>>>>))]
public virtual int? LineID { get; set; }
public abstract class lineID : IBqlField { }
[PXDBInt(IsKey = true)]
[PXUIField(DisplayName = "Inventory ID")]
[PXSelector(
typeof(Search2<InventoryItem.inventoryID,
LeftJoin<ProductLineItem,
On<ProductLineItem.lineID, Equal<Current<ProductLineItem.lineID>>,
And<ProductLineItem.inventoryID, Equal<InventoryItem.inventoryID>>>>,
Where<InventoryItem.itemStatus, Equal<InventoryItemStatus.active>,
And<ProductLineItem.lineID, IsNull>>>),
new Type[] {
typeof(InventoryItem.inventoryCD),
typeof(InventoryItem.descr)
},
SubstituteKey = typeof(InventoryItem.inventoryCD))]
public virtual int? InventoryID { get; set; }
public abstract class inventoryID : IBqlField { }
// ...
}
然后在一个非常简单的 FormDetail 入口页面中实现这些。
public class ProductLineEntry : PXGraph<ProductLineEntry, ProductLine>
{
public PXSelect<ProductLine> ProductLines;
public PXSelect<ProductLineItem,
Where<ProductLineItem.lineID,
Equal<Current<ProductLine.lineID>>>> ProductLineItems;
}
ProductLineItem.inventoryID 上的 PXSelector 提供尚未添加到当前产品线的活动项目。 However, when the Selector is written like this attempting to Delete an item from the grid results in the red "x" indicator appearing but the record is never actually removed.
将 PXSelector 更改为更基本的没有 Search2<>...
[PXSelector(typeof(InventoryItem.inventoryID),
typeof(InventoryItem.inventoryCD),
typeof(InventoryItem.descr),
SubstituteKey = typeof(InventoryItem.inventoryCD))]
...记录正常删除
如何在选择器中使用搜索<> BQL 并且仍然能够从详细信息网格中删除记录?
问题的发生是因为 ProductLineItem.InventoryID 字段是关键字段,并且为此字段定义的 BQL 搜索未 returning InventoryItem 为您尝试删除的 ProductLineItem 记录选择。
框架作为 Delete 操作的一部分所做的第一件事是调用 FieldUpdating 和 FieldUpdated 所有已删除记录键字段的处理程序。在您的情况下,这些处理程序由于 PXSelectorAttribute 无法找到为删除的 ProductLineItem[=30= 选择的 InventoryItem 而失败] 记录。有关详细信息,请参阅 Acumatica API Reference。
解决此问题的最简单方法是将 ProductLineItem.InventoryID 字段上的 BQL 搜索修改为 return 两个尚未添加到的活动项目当前产品线和为当前 ProductLineItem 记录选择的项目:
Where2<Where<InventoryItem.itemStatus, Equal<InventoryItemStatus.active>,
And<ProductLineItem.lineID, IsNull>>>,
Or<InventoryItem.inventoryID, Equal<Current<ProductLineItem.inventoryID>>>>