Acumatica-从DAC扩展插件默认更新ImageUrl

Acumatica-从DAC扩展插件默认更新ImageUrl,acumatica,Acumatica,如果在某些条件下发现库存项目ImageUrl为空,我将尝试更新它。我已经在Item类屏幕中添加了一个名为UsrStyleImg的Usr字段。此字段用于项目的基本图像,并存储在数据库中。我想要的功能是,如果清单项目在ImageUrl中没有图像,那么它将默认为与ItemClassID连接的UsrStyleImg。ItemClassID也可以在库存项目屏幕上找到。以下是我在InventoryItemMaint图中的代码: protected void InventoryItem_ImageUrl_Fi

如果在某些条件下发现库存项目ImageUrl为空,我将尝试更新它。我已经在Item类屏幕中添加了一个名为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;
      }
    }
protectedvoid InventoryItem\u ImageUrl\u FieldDefaulting(PXCache缓存,PXFieldDefaultingEventArgs e)
{
var行=(InventoryItem)e.row;
if(row==null)返回;
var item=(INItemClass)PXSelect.Select(Base,row.itemsclassid);
var image=PXSelect.Select(Base,row.ImageUrl);
如果(图像!=null)
返回;
否则{
e、 NewValue=item.GetExtension().UsrStyleImg;
}
}
代码编译得很好,但当我使用一个项目进行测试时,如果该项目附加了一个项目类,并且INItemClass表中有一个名为UsrStyleImg的图像,那么它不会填充到库存项目表或库存项目屏幕中的imageUrl中。我也尝试过使用FieldSelecting和e.ReturnValue,结果仍然相同


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

尝试使用行选择事件

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);
                    }                        
                }
            }
        }
    }
}
protected virtual void inventory item_rowselection(PXCache发送方,PXrowselectioningEventArgs e)
{
InventoryItem行=e.作为InventoryItem的行;
//防止无限循环的额外检查
if(row!=null&&!string.IsNullOrWhiteSpace(row.InventoryCD)&&Base.Item.Cache.GetStatus(row)==PXEntryStatus.Notchanged)
{
如果(!string.IsNullOrWhiteSpace(row.ItemClassID))
{
//如果在行选择期间进行选择,则必须始终使用PXConnectionScope
使用(新的PXConnectionScope())
{
//如果要在.Select中传入值,请使用Required而不是Current。
INItemClass itemClass=PXSelectReadonly.Select(Base,row.ItemClassID);
if(itemClass!=null&&string.IsNullOrWhiteSpace(row.ImageUrl))
{
INItemClassExt itemclasext=itemClass.GetExtension();
//防止不必要的更新(如果为空)
如果(!string.IsNullOrWhiteSpace(itemClassExt.UsrStyleImg))
{
row.ImageUrl=itemClassExt.UsrStyleImg;
//强制在缓存中设置状态,否则它将无限循环
Base.Item.Cache.SetStatus(行,PXEntryStatus.Updated);
基本项更新(行);
}                        
}
}
}
}
}

我尝试了这个,它发布了,但是图像仍然没有从INItemClassExt中提取。我尝试将PXSelect更改为PXSelectReadonly.Select(Base,row.itemsclassid);因为itemClassID保存在InventoryItem DAC和当前视图的屏幕上,但是我得到了相同的结果。我已经更新了我的答案。这应该行得通。但是,更新行选择事件中的值可能会产生不可预见的后果。仍无法在中导入图像。这是否需要拉入用于上载的附加文件的更新?如果您尝试在我们的项目屏幕上使用操作,并且错误显示:另一个进程已更新“库存项目”记录,也会发生错误。您的更改将丢失。在行选择上执行此操作可能会导致更多问题,而不是解决方案。