【问题标题】:Acumatica - FieldDefaulting update ImageUrl from DAC extensionAcumatica - FieldDefaulting 从 DAC 扩展更新 ImageUrl
【发布时间】:2018-04-25 23:40:37
【问题描述】:

如果在某些情况下发现库存项目 ImageUrl 为空,我正在尝试更新它。我在 Item Class 屏幕中添加了一个名为 UsrStyleImg 的 Usr 字段。此字段用于项目的基本图像,并存储在数据库中。我想要的功能是,如果库存项目在 ImageUrl 中没有图像,那么它将默认为与 ItemClassID 连接的 UsrStyleImg。 ItemClassID 也可以在库存项目屏幕上找到。这是我在 InventoryItemMaint 图中的代码:

protected void InventoryItem_ImageUrl_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
    {

      var row = (InventoryItem)e.Row;
      if (row == null) return;
      var item = (INItemClass)PXSelect<INItemClass, Where<INItemClass.itemClassID, Equal<Current<InventoryItem.itemClassID>>>>.Select(Base, row.ItemClassID);
      var image = PXSelect<InventoryItem, Where<InventoryItem.imageUrl, Equal<Current<InventoryItem.imageUrl>>>>.Select(Base, row.ImageUrl);
      if (image != null)
        return;
      else {
        e.NewValue = item.GetExtension<INItemClassExt>().UsrStyleImg;
      }
    }

代码编译得很好,但是当我用一个附加了一个项目类的项目进行测试时,它不会填充到库存项目表或库存项目屏幕中找到的 imageUrl。我也尝试过使用 FieldSelecting 并使用 e.ReturnValue 仍然得到相同的结果。

如果我需要更多说明,请告诉我。

【问题讨论】:

    标签: acumatica


    【解决方案1】:

    尝试使用 RowSelecting 事件

    protected virtual void InventoryItem_RowSelecting(PXCache sender, PXRowSelectingEventArgs e)
    {
        InventoryItem row = e.Row as InventoryItem;
    
        //Extra checks to prevent infinite loops
        if (row != null && !string.IsNullOrWhiteSpace(row.InventoryCD) && Base.Item.Cache.GetStatus(row) == PXEntryStatus.Notchanged)
        {
            if (!string.IsNullOrWhiteSpace(row.ItemClassID))
            {
                //You must always use a PXConnectionScope if Selecting during RowSelecting
                using (new PXConnectionScope())
                {
                    //If you're going to pass in a value in .Select, use Required instead of Current.
                    INItemClass itemClass = PXSelectReadonly<INItemClass, Where<INItemClass.itemClassID, Equal<Required<INItemClass.itemClassID>>>>.Select(Base, row.ItemClassID);
    
                    if (itemClass != null && string.IsNullOrWhiteSpace(row.ImageUrl))
                    {
                        INItemClassExt itemClassExt = itemClass.GetExtension<INItemClassExt>();
    
                        //To prevent unneeded update if it's blank
                        if (!string.IsNullOrWhiteSpace(itemClassExt.UsrStyleImg))
                        {
                            row.ImageUrl = itemClassExt .UsrStyleImg;
    
                            //Force set the status in the Cache, otherwise it infinite loops
                            Base.Item.Cache.SetStatus(row, PXEntryStatus.Updated);
                            Base.Item.Update(row);
                        }                        
                    }
                }
            }
        }
    }
    

    【讨论】:

    • 我试过这个并发布了,但图像仍然没有从 INItemClassExt 中提取。我尝试将 PXSelect 更改为 PXSelectReadonly>>>.Select(Base, row.ItemClassID);因为 itemClassID 保存在 InventoryItem DAC 和当前视图的屏幕上,但我得到了相同的结果。
    • 我已经更新了我的答案。这应该有效。但是,更新 RowSelecting 事件中的值可能会产生无法预料的后果。
    • 仍然没有导入图像。这是否需要拉入更新附件以供上传?
    • 如果您尝试在我们的项目屏幕上使用操作并且错误显示为:另一个进程已更新“库存项目”记录,也会发生错误。您的更改将会丢失。
    • 在 RowSelecting 上执行此操作似乎导致的问题多于解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 2018-03-05
    • 1970-01-01
    相关资源
    最近更新 更多