【问题标题】:Update Custom Field on Popup在弹出窗口中更新自定义字段
【发布时间】:2018-04-13 17:43:53
【问题描述】:

我在更新弹出模型中的自定义字段时遇到问题。

我在客户页面中创建了一个客户字段“UsrCustomerNote”,它创建了以下 DAC 扩展。

namespace PX.Objects.CR
{
    public class BAccountExt : PXCacheExtension<PX.Objects.CR.BAccount>
    {
        #region UsrCustomerNote
        [PXDBString(1000)]
        [PXUIField(DisplayName="Customer Note")]
        public virtual string UsrCustomerNote { get; set; }
        public abstract class usrCustomerNote : IBqlField { }
        #endregion
    }
}

我像这样在客户页面中添加了字段控件。

我的要求是当我选择客户时,在服务订单页面的新弹出对话框中显示此 CustomerNote 字段值。

首先,我在名为“ServiceOrderEntry”的服务订单的图形扩展中创建了一个视图名称 CustomerSelector。

public PXFilter<BAccount> CustomerSelector;

所以,我在服务订单页面中添加了一个弹出面板。并在弹出窗口中添加了自定义字段。

然后,我在服务订单页面中为字段 CustomerID 添加了 Field_Updated 事件处理程序。这是ServiceOrderEntry Graph扩展的完整代码sn-p。

using System;
using PX.Objects;
using PX.Data;
using PX.Objects.AR;
using PX.Objects.CR;

namespace PX.Objects.FS
{
  public class ServiceOrderEntry_Extension : PXGraphExtension<ServiceOrderEntry>
  {
        #region Event Handlers
        public PXFilter<BAccount> CustomerSelector;

        protected void FSServiceOrder_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
        {
            if (InvokeBaseHandler != null)
                InvokeBaseHandler(cache, e);
            var row = (FSServiceOrder)e.Row;
            if (CustomerSelector.AskExt(delegate
            {
                BAccountEnq bAccountEnq = PXGraph.CreateInstance<BAccountEnq>();
                BAccount bAccount = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Required<BAccount.bAccountID>>>>.Select(bAccountEnq, row.CustomerID);
                CustomerSelector.Current = bAccount;
                CustomerSelector.Current.GetExtension<PX.Objects.CR.BAccountExt>().UsrCustomerNote = (string)bAccount.GetExtension<PX.Objects.CR.BAccountExt>().UsrCustomerNote;
                /*
                 * The below one didn't work too
                 */
                //CustomerSelector.Cache.SetValue<PX.Objects.CR.BAccountExt.usrCustomerNote>(CustomerSelector.Current, (string)bAccount.GetExtension<PX.Objects.CR.BAccountExt>().UsrCustomerNote);
                CustomerSelector.Update(CustomerSelector.Current);

            }) == WebDialogResult.OK)
            {
                //CODE TO UPDATE THE VALUE IN CUSTOMERS PAGE
            }
        }
        #endregion
  }
}

它会加载弹出面板,但 TextField 是空的,即使我可以看到该字段的值已在调试模式下更新。

我需要帮助来找出我缺少的东西。

【问题讨论】:

    标签: acumatica


    【解决方案1】:

    我会建议将 Where 条件添加到 Filter View 而不是在 Initialization Delegate 中设置 current:

    public PXFilter<BAccount,Where<BAccount.bAccountID,Equal<Current<FSServiceOrder.customerID>>>> CustomerSelector;
    

    您还需要更新客户维护中的值并保存。这是您如何做到这一点的示例。

    if (CustomerSelector.AskExt(true) == WebDialogResult.OK)
    {
        CustomerMaint customersMaint = PXGraph.CreateInstance<CustomerMaint>();
        var updatedValue = PXCache<BAccount>.GetExtension<BAccountExt>(CustomerSelector.Current);
        Customer customer = customersMaint.BAccount.Search<Customer.bAccountID>(CustomerSelector.Current.bAccountID);
        var valueToUpdate = PXCache<BAccount>.GetExtension<BAccountExt>(CustomerSelector.Current);
        valueToUpdate.UsrCustomerNote = updatedValue.UsrCustomerNote;
        customersMaint.BAccount.Update(customer);
        customersMaint.Save.PressButton();
    }
    

    我还没有测试过这段代码。

    【讨论】:

    • PXFilter 只取 Table 作为参数,因为它只有一条记录,所以代码只能这样,不能添加 Where 子句。 PXFilter&lt;BAccount&gt; CustomerSelctor; 我什至添加了一个自定义 DAC 来简化这个 using System; using PX.Data; namespace CustomerNote { [Serializable] public class CustomerNoteDAC : IBqlTable { [PXDBString(4000)] [PXUIField(DisplayName = "Notes")] public virtual string UsrCustomerNote{ get; set; } public abstract class usrCustomerNote : IBqlField { } } }
    • public PXFilter&lt;CustomerNoteDAC&gt; CustomerSelector; protected void FSServiceOrder_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler) { if (InvokeBaseHandler != null) InvokeBaseHandler(cache, e); var row = (FSServiceOrder)e.Row; BAccountEnq bAccountEnq = PXGraph.CreateInstance&lt;BAccountEnq&gt;(); BAccount bAccount = PXSelect&lt;BAccount, Where&lt;BAccount.bAccountID, Equal&lt;Required&lt;BAccount.bAccountID&gt;&gt;&gt;&gt;.Select(bAccountEnq, row.CustomerID);
    • CustomerSelector.Current.UsrCustomerNote = (string)bAccount.GetExtension&lt;PX.Objects.CR.BAccountExt&gt;().UsrCustomerNote; CustomerSelector.Update(CustomerSelector.Current); if (CustomerSelector.AskExt(true)== WebDialogResult.OK) { } }
    • @BikashLama 你还不能更新这个字段吗?我从你的 cmets 那里不明白现在有什么问题。
    • 是的,该字段仍未更新。我什至将 Dialog 的 AutoReload 事件更改为“True”,但这也不起作用。
    【解决方案2】:

    我发现了问题所在。 Dialog 的 LoadOnDemand 属性需要设置为 true。代码从一开始就很好。感谢@Samvel Petrosov 对此的帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 2019-10-07
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 1970-01-01
      • 2011-05-08
      相关资源
      最近更新 更多