【问题标题】:Unable to Copy UDF from POLine (PO301000) to POReceiptLine(PO302000) on "Enter PO Receipt" Action无法在“输入采购订单收据”操作中将 UDF 从 POLine (PO301000) 复制到 POReceiptLine(PO302000)
【发布时间】:2021-07-25 19:28:25
【问题描述】:

我在 POLine 和 POReceiptLine 中创建了 2 个 UDF,我试图在 PO 屏幕 (PO301000) 中的“输入 PO Receipt”操作中将这些 UDF 的值从 POLine 复制到 POReceiptLine。我的代码正在执行,但值没有被复制。请推荐,谢谢

protected void POReceipt_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
    {
      
      var row = (POReceipt)e.Row;

            POReceiptLine row1 = new POReceiptLine();
            if (Base.Document.Current != null)
            {
                foreach (POReceiptLine tran in Base.transactions.Select())
                {
                    POLine xPOLine = PXSelect<POLine,
                        Where<POLine.orderNbr, Equal<Current<POLine.orderNbr>>,
                        And<POLine.orderType, Equal<Current<POLine.orderType>>>>>.Select(Base, tran.PONbr, tran.POType);
                    if (xPOLine != null)
                    {
                        POLineExt poLineExt = PXCache<POLine>.GetExtension<POLineExt>(xPOLine);
                        POReceiptLineExt poReceiptLineExt = PXCache<POReceiptLine>.GetExtension<POReceiptLineExt>(row1);

                        poReceiptLineExt.UsrWarrantyTerms = poLineExt.UsrWarrantyTerms;
                        poReceiptLineExt.UsrVendorWarrantyDate = poLineExt.UsrVendorWarrantyDate;
                    }
                    return;
                }

            }


        }

####...第 2 节..####### 我也尝试过使用下面的代码,但没有运气。

 protected virtual void _(Events.FieldDefaulting<POReceiptLineExt.usrWarrantyTerms> e)
        {
            POReceiptLine row = (POReceiptLine)e.Row;
            if (row != null)
            {
                POReceiptLineExt receiptLineExt = row.GetExtension<POReceiptLineExt>();
                POLine line = SelectFrom<POLine>
                    .Where<POLine.pONbr.IsEqual<@P.AsString>
                    .And<POLine.lineNbr.IsEqual<@P.AsInt>>>
                    .View.Select(Base, row.PONbr, row.POLineNbr);
                POLineExt lineExt = line.GetExtension<POLineExt>();
                if (lineExt?.UsrWarrantyTerms != null && receiptLineExt != null)
                {
                    e.NewValue = receiptLineExt.UsrWarrantyTerms;
                }
            }
        }
        protected void POReceiptLine_ReceiptNbr_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            var row = (POReceiptLine)e.Row;
            if (row == null) return;
            cache.SetDefaultExt<POReceiptLineExt.usrWarrantyTerms>(row);
        }

【问题讨论】:

  • 你试过了吗:Base.SetValueExt(viewName,Data/row,Value)
  • 尊敬的 JvD,请问您的反馈更具体,我应该在我的代码中使用 SetValueExt 的确切位置。实际上,我不确定在哪里需要将 SetValueExt 用于 mu UDF。谢谢

标签: acumatica acumatica-kb


【解决方案1】:

不确定你的版本,所以我会根据我正在运行的 2020R2 版本来回答。

观察: 您似乎在交易视图中的第一个 POReceiptLine 之后返回。更重要的是,在 POReceiptLine_RowPersisting 事件中放置似乎更合适,您不必在 RowPersisting 中执行 foreach。最后,在我的脑海中,如果您正在处理被持久化的记录,我不记得是否需要在持续执行此操作时更新缓存,但是您正在处理不同的记录,这意味着您可能需要更新在 RowPersisting 事件中变得棘手的缓存。 (例如,您可能不知道其他缓存是否已被持久化。)

动作流程: POOrderEntry 包含操作 CreatePOReceipt ,该操作反过来初始化 POReceiptEntry 并通过 CreateReceiptFrom(...) 从订单创建收据,然后调用 AddPOLine(.. .)。随后,POReceiptLine 通过 line = this.transactions.Insert(line); 创建。

建议: 在 2020R2 中,您的代码似乎属于 POReceiptEntry,但您没有指定放置它的位置。如果您将它放在 POOrderEntry 中,则该事件永远不会触发。

尝试在 POReceiptEntry 中添加类似的内容(对其他字段也进行类似操作)。

protected virtual void _(Events.FieldDefaulting<POReceiptLineExt.UsrWarrantyTerms> e)
{
    POReceiptLine row = (POReceiptLine) e.Row;
    if(row != null)
    {
        POReceiptLineExt receiptLineExt = row.GetExtension<POReceiptLineExt>();
        POLine line = SelectFrom<POLine>
            .Where<POLine.pONbr.IsEqual<@P.AsString>
            .And<POLine.lineNbr.IsEqual<@P.AsInt>>>
            .View.Select(Base, row.PONbr, row.POLineNbr);
        POLineExt lineExt = line.GetExtension<POLineExt>();
        if(lineExt?.UsrWarrantyTerms != null && receiptLineExt != null)
        {
            e.NewValue = receiptLineExt.UsrWarrantyTerms;
        }
    }
}

由于 PONbr 和 LineNbr 字段可能尚未设置,您可能需要在适当的位置为这两个字段使用 SetDefaultExt。 (我建议也许在 POReceiptLine.POLineNbr FieldUpdated 事件中尝试。)我相信来自 POOrderEntry 的操作的插入已经填写了字段,但在创建 POReceiptLine 记录的所有方式中可能并非如此,所以您要确保每次都在保证的情况下设置值。

【讨论】:

  • 亲爱的Brian,我使用的是2020 R2,我已经尝试过你的建议,但我发现只是运气。请您检查问题,我已根据您的建议对问题进行了一些编辑,如果出现任何问题,请告诉我们,我会相应地做。谢谢
【解决方案2】:

我已经找到了解决这个问题的方法,即通过使用字段级事件并从字段级事件调用函数,下面的代码对我来说工作得很好。谢谢。

protected void POReceiptLine_POLineNbr_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            var row = (POReceiptLine)e.Row;
            CarryForwardFromPO(row);

        }

        public void CarryForwardFromPO(POReceiptLine row)
        {
            if (row.PONbr == null || row.POType == null || row.POLineNbr == null)
                return;
            POReceiptLineExt _polext = PXCache<POReceiptLine>.GetExtension<POReceiptLineExt>(row);

            if (row.PONbr != null)
            {
                POLine xPOLine = PXSelect<POLine,
                            Where<POLine.orderNbr, Equal<Required<POLine.orderNbr>>,
                            And<POLine.orderType, Equal<Required<POLine.orderType>>,
                            And<POLine.lineNbr, Equal<Required<POLine.lineNbr>>>>>>.Select(Base, row.PONbr, row.POType, row.POLineNbr);

                if (xPOLine != null)
                {
                    POLineExt xPOLineExt = PXCache<POLine>.GetExtension<POLineExt>(xPOLine);
                    if (xPOLineExt != null)
                    {
                        if (xPOLineExt.UsrVendWarrantyType != null)
                        {
                            _polext.UsrVendWarrantyType = xPOLineExt.UsrVendWarrantyType.Trim();
                        }

                        if (xPOLineExt.UsrWarrantyTerms != null)
                        {
                            _polext.UsrWarrantyTerms = xPOLineExt.UsrWarrantyTerms.Trim();
                        }
                        if (xPOLineExt.UsrVendorWarrantyDate != null)
                        {
                            _polext.UsrVendorWarrantyDate = xPOLineExt.UsrVendorWarrantyDate;
                        }
                    }
                }
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-31
    • 1970-01-01
    • 2020-11-24
    • 1970-01-01
    • 1970-01-01
    • 2017-06-01
    • 1970-01-01
    • 2016-05-06
    相关资源
    最近更新 更多