需要遍历SO行 - 并使用自定义字段进行检查

时间:2018-04-06 06:58:57

标签: acumatica

只有在输入SO行表中的某些自定义字段并使用其他表格检查时,我才需要将销售订单标记为打开。

我创建了一个活动 - 我如何在这里遍历SO Lines及其扩展字段?

//    protected void SOOrder_Hold_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
//    {
//      if(InvokeBaseHandler != null)
//        InvokeBaseHandler(cache, e);
//      var row = (SOOrder)e.Row;
//      string ordtype = row.OrderType;
//      string ordnbr = row.OrderNbr;

//      if (row.Hold == false)/
//      {
//           foreach (SOLine record in
//                    PXSelectReadonly<SOLine,
//                    Where<SOLine.orderType, Equal<Required<SOLine.orderType>>, 
//                    And<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>>>>.Select(Base, ordtype, ordnbr))
//           {
//                             cache.RaiseExceptionHandling<SOOrder.hold>(
//                            row, row.Hold,
//                              new PXSetPropertyException("Product Module Sample Project Check", PXErrorLevel.Warning));    
//           }
//        }    
//    }

2 个答案:

答案 0 :(得分:2)

我实际上建议使用FieldVerifying事件

protected virtual void SOOrder_Hold_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e, PXFieldVerifying del)
{
    //Calls other handlers if they exist.
    //Important for Acumatica Events / Other Customizations
    if (del != null)
    {
        del(sender, e);
    }

    SOOrder row = e.Row as SOOrder;

    if (row != null && !((e.NewValue as bool?) ?? false))
    {
        bool allFieldsProper = true;

        SOLine line;
        SOLineExtension lineExt;

        foreach (PXResult<SOLine, INItemCost> res in Base.Transactions.Select())
        {
            line = res[0] as SOLine;
            lineExt = line.GetExtension<SOLineExtension>();

            if (lineExt.UsrField != "Some Value")
            {
                allFieldsProper = false;
                //No point in further evaluation if 1 is wrong
                break;
            }
        }

        if (!allFieldsProper)
        {
            throw new PXSetPropertyException<SOOrder.hold>("Error", PXErrorLevel.Error)
        }
    }
}

答案 1 :(得分:0)

SO行存储在DataView的交易SOOrderEntryGraph中。 要使用它们并检查任何自定义字段(来自扩展程序),您可以执行以下操作:

protected void SOOrder_Hold_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
    //if(InvokeBaseHandler!=null)   - remove comments from these lines if you need to call the base method
    //    InvokeBaseHandler(cache,e);  
    if(e.Row!=null)
    {
        SOOrder currentOrder = (SOOrder) e.Row;
        foreach (IEnumerator<PXResultSet<SOLine>> linesEnumerator in this.Base.Transactions.Select().GetEnumerator())
        {
            while (linesEnumerator.MoveNext())
            {
                SOLine currentLine = (SOLine)linesEnumerator.Current;
                var currentLineExt = PXCache<SOLine>.GetExtension<SOLineExt>(currentLine);// replace SOLineExt with the name of your DAC's Cache Extension's class name
                //----
                // Here add your checking 
                //----
            }
        }
    }
}