如何从另一个事件处理程序调用SetPropertyException?

时间:2017-01-29 22:55:06

标签: acumatica

下面是我的代码,用于将输入到我的UsrWLAmt字段中的任何值插入到我的BudgetGrid中,表示字段值的历史记录。

我想发出警告,提示用户在BudgetGrid历史记录中的详细信息字段中输入值

protected void PMProject_UsrWLAmt_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
  if(InvokeBaseHandler != null)
    InvokeBaseHandler(cache, e);
  var row = (PMProject)e.Row;
        PMProject con = Base.Project.Current;
        PX.Objects.PM.ProjectExt item = con.GetExtension<PX.Objects.PM.ProjectExt>();
        if (item.UsrWLAmt > 0)
        {
            atcBudgetHis bud = new atcBudgetHis();
            bud.CreatedDateTime = DateTime.Now;
            bud.Value = item.UsrWLAmt;
            BudgetGrid.Insert(bud);
            // to attach the exception object to the field
            BudgetGrid.View.Cache.RaiseExceptionHandling<atcBudgetHis.details>(
            bud, " ",
            new PXSetPropertyException(
            "Please specifiy reason for budget change.",
            PXErrorLevel.Warning));

        }
    }

我还试过BudgetGrid.Cahce.RaiseExceptionHandling

上面的代码不会引发任何跟踪错误。

编辑:

PXUIFieldAttribute.SetWarning<atcBudgetHis.details>(BudgetGrid.Cache, null, "Please specifiy reason for budget change.");

enter image description here

适用于所有行但

PXUIFieldAttribute.SetWarning<atcBudgetHis.details>(BudgetGrid.Cache, bud, "Please specifiy reason for budget change.");

不会发出任何警告。

我可以在网格上方创建另一个字段来插入注释,但有没有办法可以为BudgetGird中的最后一行设置警告?

4 个答案:

答案 0 :(得分:2)

您似乎尝试在事件被调用时在网格中不存在的DAC实例上设置警告。

您是否尝试在事件处理程序参数中返回的现有行上设置警告?

PXUIFieldAttribute.SetWarning<atcBudgetHis.details>(BudgetGrid.Cache, row, "Please specify reason for budget change.");

警告适用于满足执行此行的条件的所有行。如果要仅显示最后一行,则必须手动检查参数中接收的行是否与数据视图中的最后一行相同,然后才执行该行的警告。

答案 1 :(得分:2)

首先,要在Acumatica中显示警告,必须使用以下事件之一:

  • FieldVerifying 并抛出PXSetPropertyException,警告只应在用户更新记录时出现

  • RowUpdating ,在PXCache上调用RaiseExceptionHandling方法,如果警告仅在用户更新记录期间出现在多个字段上

  • RowSelected ,在PXCache上调用RaiseExceptionHandling方法,如果警告应始终出现在多个字段上,直到用户解决警告原因

我想对于您的特定情况,RowSelected可能最有效地不断显示Notes列中所有空单元格的警告:

public void atcBudgetHis_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
    atcBudgetHis row = e.Row as atcBudgetHis;
    if (row == null) return;

    if (string.IsNullOrEmpty(row.Details))
    {
        sender.RaiseExceptionHandling<atcBudgetHis.details>(row, string.Empty,
            new PXSetPropertyException("Please specify reason for budget change.", PXErrorLevel.Warning));
    }
    else
    {
        sender.RaiseExceptionHandling<atcBudgetHis.details>(row, row.Details, null);
    }
}

答案 2 :(得分:0)

解决方案是为我的网格使用RowInserted事件并将行变量传递给SetWarning

答案 3 :(得分:0)

您需要更改此代码:

BudgetGrid.Insert(bud);
// to attach the exception object to the field
BudgetGrid.View.Cache.RaiseExceptionHandling<atcBudgetHis.details>(bud, " ",new PXSetPropertyException("Please specifiy reason for budget change.",PXErrorLevel.Warning));

对于这样的事情:

bud = BudgetGrid.Insert(bud); //you need to get the "bud" which is in the cache
// to attach the exception object to the field
BudgetGrid.View.Cache.RaiseExceptionHandling<atcBudgetHis.details>(bud, " ",new PXSetPropertyException("Please specifiy reason for budget change.",PXErrorLevel.Warning));
相关问题