我在Stock Item页面InventoryItem.UsrLeadTime上创建了一个自定义字段作为组合框,如下所示:
[PXDBString(10)]
[PXUIField(DisplayName="Lead Time")]
[PXStringList(new string[] { "4", "7", "10" },
new string[] { "4", "7", "10" },
MultiSelect = false, ExclusiveValues = false)]
我还在SO Order Entry SOLine网格上创建了一个自定义字段作为combox,SOLine.UsrLeadTimeSOLine,如下所示:
[PXDBString(10)]
[PXUIField(DisplayName="Lead Time")]
[PXStringList(new string[] { "4", "7", "10" },
new string[] { "4", "7", "10" },
MultiSelect = false, ExclusiveValues = false)]
我试图根据在销售订单上输入新行时选择的库存ID,将SOLINE网格上的UsrLeadTimeSoline的默认值设置为UsrLeadTime从库存项目指定的值 . 我在SOOrderEntry图扩展上的代码如下:
protected virtual void SOLine_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
{
SOLine row = (SOLine)e.Row;
using (new PXConnectionScope())
{
InventoryItem invleadTime = PXSelect<InventoryItem,
Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>
.Select(Base, row.InventoryID);
if (invleadTime != null)
{
PX.Objects.IN.InventoryItemExt ext = PXCache<InventoryItem>.GetExtension<InventoryItemExt>(invleadTime);
sender.SetValue<SOLineExt.usrLeadTimeSOLine> (row,ext.UsrLeadTime);
Base.Transactions.Update(row);
//SOLineExt rowExt = sender.GetExtension<SOLineExt>(row);
//rowExt.UsrLeadTimeSOLine = ext.UsrLeadTime;
//Base.Transactions.Update(row);
}
else
{
throw new PXException("invleadTime is null");
}
}
}
我抛出了else throw异常作为一个想法,以确保我的查询返回结果 . 如果没有else,代码将正确编译并且Sales Order页面正确运行,但是当您添加新行并选择inventoryID时,SOLINE网格中的提前期值SOLine.UsrLeadTimeSOLine仍为空白,即使InventoryID具有Lead的值时间,InventoryItem.UsrLeadTime,在Stock Items页面上 .
添加else throw异常后,当您添加新的Sales Order Line时,会立即显示异常,并将invleadTime声明为null . 选择InventoryID会导致SOLINE网格的提前期值SOLine.UsrLeadTimeSOLine设置为等于Stock Items页面InventoryItem.UsrLeadTime的提前期值 . 换句话说,它按预期工作 .
此外,在“保存”期间,它会创建一个新的空白行,并引发有关必填字段为空的错误 . 删除空白行并保存正常 . 我对包含throw异常的页面的行为不太感兴趣,除了代码似乎工作的事实,因为在包含throw异常时设置我的值 .
任何人都可以建议修改我的代码而不使用else会导致它正确地将SOLine.UsrLeadTimeSOLine的值设置为等于InventoryItem.UsrLeadTime . 谢谢
3 回答
如果您没有提前期的默认值和/或不希望该字段是必需的,我将使用inventoryID的“FieldUpdated”事件来执行此操作 .
像下面这样的东西也会起作用:
如果更改库存ID,这还将允许重置提前期值(按原样)
您应该只需要将这些属性添加到您的soline usr字段中......
通过使用默认...添加PXFormula更改销售线库存ID,它将重新激活您的默认值 . 这样可以更轻松地从DAC控制默认值,而无需在图表中添加任何额外的行 .
我建议使用FieldDefaulting事件来设置默认值 . 在其他事件中尝试这样做可能会导致意想不到的副作用 .