Update Custom Field on Popup

烂漫一生 提交于 2021-02-05 11:34:08

问题


I am having problem in updating custom field in popup model.

I created a customer field 'UsrCustomerNote' in Customers page which created the following DAC Extension.

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
    }
}

And I added field control in Customers page like this.

My requirement is to display this CustomerNote field value in new popup dialog in Service Orders page when I select the Customer.

First I created a view name CustomerSelector in Graph Extension for Service Orders called 'ServiceOrderEntry'.

public PXFilter<BAccount> CustomerSelector;

So, I added a Popup Panel in Service Order page. And added the custom field in popup.

Then I added an Field_Updated Event Handler for the field CustomerID in Service Orders page. And here is the full code snippet of of ServiceOrderEntry Graph extension.

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
  }
}

It loads the popup panel but the TextField is empty, even though I can see that the field's value has been updated in debug mode.

I need the help to find out what I am missing.


回答1:


I will suggest to add Where condition to the Filter View instead of setting current in the Initialization Delegate:

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

Also you need to update value in the Customer's Maintenance and save it. Here is example how you can do it.

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();
}

I have not tested this code yet.




回答2:


I figured out the problem. It was the LoadOnDemand property that needs to be set to true for Dialog. The code was fine from beginning. Thanks @Samvel Petrosov for your help to this.



来源:https://stackoverflow.com/questions/49822530/update-custom-field-on-popup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!