0
votes

I am trying to set a custom field on a brand new BAccount object created via the action ConvertToBAccount() in the Contact BLC. I've tried quite a few different things including overriding the action and trying to set the value on the object after the action is complete and navigates to the BAccount BLC. I found that I can't set the value on the override because there is no record in the database until the user manually saves, and when I try to set the value after the action, it sets the field, but does not show the new value on the screen when the BAccount BLC is done loading.

How can I set an extension field for a new BAccount created via the ConvertToBAccount() action on the Contacts BLC?

DAC Extension:

public class BAccountExt : PXCacheExtension<PX.Objects.CR.BAccount>
{
        #region UsrHomeCampus
        [PXDBInt]
        [PXUIField(DisplayName="Home Campus")]
        [PXSelector(typeof(Search<PX.Objects.GL.Branch.branchID>),
        typeof(PX.Objects.GL.Branch.branchCD),
        SubstituteKey = typeof(PX.Objects.GL.Branch.branchCD))]
        public virtual int? UsrHomeCampus { get; set; }
        public abstract class usrHomeCampus : IBqlField { }
        #endregion
}

BLC Code:

public class BusinessAccountMaint_Extension : PXGraphExtension<BusinessAccountMaint>
{
    #region Event Handlers
    protected void Contact_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
    {
        Contact row = (Contact)e.Row;

        if (row.ContactID > 0 && Base.CurrentBAccount.Current.BAccountID < 0)
        {
            Base.CurrentBAccount.Current.GetExtension<BAccountExt>().UsrHomeCampus = row.GetExtension<ContactExt>().UsrHomeCampus;
            //Save record in database
            Base.Actions.PressSave();
            //Cause page refresh
            Base.Actions.PressCancel();
        }
    }
    #endregion
}
1
Can you please add the full exception with Stack Trace. - Samvel Petrosov
I don't get any exception, it just doesn't set a value to the extension field. The segment I showed was just from the Watch window in Visual Studio. - EricP.
Your Dac Extension is for BAccount or Contact? Your view's name is CurrentBAccount but Dac Extension is ContactExt - Samvel Petrosov
It is for BAccount. Thank you for catching that. I will correct it above, but the situation remains. It does set the value, but it does not display the value I set. - EricP.

1 Answers

2
votes

When a BAccount is being created from Contact by ConvertToBAccount() method the BAccountID of the newly created BAccount is being set to Contact's BAccountID field.

You should take that BAccount for example by querying something like this

BAccount bAccount = PXSelect<BAccount,Where<BAccount.bAccountID,Equal<Required<BAccount.bAccountID>>>.Select(graph,contactObject.BAccountID);

Then get you extension like this:

BAccountExt acc = PXCache<BAccount>.GetExtension<BAccountExt>(bAccount);

And set the values that you need and then update the BAccount in some way like this:

this.Base.BAccountsView.Update(bAccount);
this.Base.Save.Press();