Acumatica-根据不同字段将复选框设置为true



我知道这是基本的东西和条件,但我对服务订单中已经存在的一行有问题。因此,我们有将导入Acumatica的服务订单,并且已经有了一条线。当在Acumatica系统中时,有人会进入服务订单屏幕(SD300100(,并在导入后进行他们想要的更改。在这种情况下,他们将更改我们创建的自定义字段"保修状态",并更改详细信息和标题中的一些值。除了从细节行导入的第一行外,我已经完成了所有工作。因此,此订单将在"人工"选项卡中插入一行。我的问题是,当我们将"保修状态"更改为"保修"时,应该在详细信息行中选中另一个名为"保修(Warranty("的自定义字段框。我对任何新插入的行都有这个功能,但我无法用现有的行获得它。我在Header和Labor行数据视图中都尝试过RowUpdated、RowUpdating、RowInserted和RowInserting。以及表头保修选择器上的FieldUpdated、FieldUpdating和Selecting,以及人工选项卡下详细信息中的warranty复选框。

这是我的代码:

public PXSelect<FSSODet,  Where<FSSODet.sOID, Equal<Current<FSSODet.sOID>>>> FSSODets;
protected void FSServiceOrder_Usrwarrstat_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (FSServiceOrder)e.Row;
if (row == null) return;
FSSODet line = FSSODets.Current;
if (line == null) return;
if (line != null){
FSServiceOrderExt rowExt = PXCache<FSServiceOrder>.GetExtension<FSServiceOrderExt>(row);
if(rowExt == null)
return;
if (rowExt.Usrwarrstat == null) 
return;
if (rowExt.Usrwarrstat == "W"){ 
cache.SetValueExt<FSSODetExt.usrwarrantydetail>(line, true);
}
}
}

这是我去这里之前最后一次尝试的方式。如果有人有不同的方法,我可以为上面提到的任何方法、RowUpdated、RowUpdating等提供代码。在这两个字段上,Commit Changes都设置为true。

简而言之,当服务订单标题中的Usrwarrstat字段设置为"W"时,我希望人工选项卡/详细信息中的Usrwarrantydetail设置为true。

更新1:所以我使用了下面的第一个答案建议,它确实将复选框更改为已选中,但无论状态如何,都会发生这种情况。我只需要检查它是否设置为"W"或"p",唯一的另一个选项是"N",所以我添加了一个复选框,如果它设置为"N"则为false。然而,它仍然将其视为真实。这是更新后的代码:

public PXSelect<FSSODetService,  Where<FSSODetService.sOID, Equal<Current<FSSODetService.sOID>>>> FSSODets;
protected void FSServiceOrder_Usrwarrstat_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (FSServiceOrder)e.Row;
if (row == null) return;
FSSODetService line = FSSODets.Current;
if (line == null) return;
if (line != null){
FSServiceOrderExt rowExt = PXCache<FSServiceOrder>.GetExtension<FSServiceOrderExt>(row);
if(rowExt == null)
return;
if (rowExt.Usrwarrstat == null) 
return;
if (rowExt.Usrwarrstat == "W" || rowExt.Usrwarrstat == "P"){ 
FSSODets.Cache.SetValueExt<FSSODetExt.usrwarrantydetail>(line, true);
}
if (rowExt.Usrwarrstat == "N"){
FSSODets.Cache.SetValueExt<FSSODetExt.usrwarrantydetail>(line, false);
}
}
}
}

总体而言,逻辑看起来不错。缓存对象不匹配可能会阻止SetValueExt工作:

// When this event handler is called by the framework
// PXCache cache object will be of type  FSServiceOrder
// because the event is bound on FSServiceOrder DAC
protected void FSServiceOrder_Usrwarrstat_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)

当您调用SetValueExt时,您应该使用匹配类型的缓存对象:

// cache reference is of type FSServiceOrder but we want to modify FSSODetExt DAC field
cache.SetValueExt<FSSODetExt.usrwarrantydetail>(line, true);
// With extensions you have to use the base DAC cache
// you already declared a DataView on FSSODet so you can use it's cache reference
FSSODets.Cache.SetValueExt<FSSODetExt.usrwarrantydetail>(line, true);

除了DAC缓存引用不匹配之外,您也有可能成功修改字段值,但另一个事件处理程序/机制在您之后再次修改它。若要检查是否可以在目标字段上声明事件处理程序,请在其中放置一个断点,然后使用visualstudio调试堆栈跟踪窗口对其进行调试。堆栈跟踪将显示哪些方法会导致字段修改。

protected void FSSODet_Usrwarrantydetail_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)

还要确保Usrwarrstat字段在ASPX文件中设置了CommitChanges=True属性,否则在屏幕上修改字段将不会执行关联的FieldUpdated事件处理程序。