【问题标题】:PXSelector with Search BQL prevents record deletion带有 Search BQL 的 PXSelector 可防止记录删除
【发布时间】:2017-04-19 21:56:36
【问题描述】:

我有 ProductLineProductLineItem 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 提供尚未添加到当前产品线的活动项目。但是,当这样编写选择器时,尝试从网格中删除项目会导致出现红色“x”指示符,但会出现 record is never actually removed

将 PXSelector 更改为没有 Search2 的更基本的选择器...

[PXSelector(typeof(InventoryItem.inventoryID),
    typeof(InventoryItem.inventoryCD),
    typeof(InventoryItem.descr),
    SubstituteKey = typeof(InventoryItem.inventoryCD))]

...记录正常删除。

如何在选择器中使用搜索 BQL 并且仍然能够从详细信息网格中删除记录?

【问题讨论】:

    标签: acumatica


    【解决方案1】:

    出现问题的原因是 ProductLineItem.InventoryID 字段是一个关键字段,并且为此字段定义的 BQL 搜索未返回为 选择的 InventoryItem ProductLineItem 您尝试删除的记录。

    框架作为 Delete 操作的一部分所做的第一件事是调用 FieldUpdatingFieldUpdated所有已删除记录关键字段的处理程序。在您的情况下,这些处理程序失败是因为 PXSelectorAttribute 无法找到为已删除的 ProductLineItem 记录选择的 InventoryItem。详情请见Acumatica API Reference

    解决此问题的最简单方法是修改 ProductLineItem.InventoryID 字段上的 BQL 搜索,以返回尚未添加到当前产品线的活动项目和为当前产品线选择的项目ProductLineItem 记录:

    Where2<Where<InventoryItem.itemStatus, Equal<InventoryItemStatus.active>,
               And<ProductLineItem.lineID, IsNull>>>,
        Or<InventoryItem.inventoryID, Equal<Current<ProductLineItem.inventoryID>>>>
    

    【讨论】:

    • 谢谢鲁斯兰。如果其他人参考这个答案,我会注意到提供的示例代码有一个小错误,即最后一个运算符不应使用 Current 并且当然与 inventoryID 而不是 lineID 进行比较:Or&lt;InventoryItem.inventoryID, Equal&lt;ProductLineItem.inventoryID&gt;&gt;
    • @NickolasHook,感谢您指出这一点 - 我已更新代码以改用 ProductLineItem.inventoryID。但是我确实相信使用 Current 运算符仍然是必要的。另外,我建议将 AutoRefresh 设置为 True,以便在 Aspx 中输入 PXSelector,以确保为所选记录显示查找网格的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    • 2012-02-07
    • 2022-12-15
    相关资源
    最近更新 更多