Skip to main content

Greetings,

I am currently working on my first proper customization and have some trouble with field values.
The plan is to include another fourth addressline in addition to the already existing three addresslines, not only in the Customer-Data but also for use in invoices and other forms.
I went ahead and wrote these two Extensions:

AddressExtension:

using PX.CS.Contracts.Interfaces;
using PX.Data.ReferentialIntegrity.Attributes;
using PX.Data;
using PX.Objects.Common.Bql;
using PX.Objects.CR.MassProcess;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects;
using System.Collections.Generic;
using System.Diagnostics;
using System;

namespace PX.Objects.CR
{
  public class AddressExt : PXCacheExtension<PX.Objects.CR.Address>
  {
    #region UsrAdressLine4
    UPXDBString(50)]
    PXUIField(DisplayName="Adresszeile 4")]

    public virtual string UsrAdressLine4 { get; set; }
    public abstract class usrAdressLine4 : PX.Data.BQL.BqlString.Field<usrAdressLine4> { }
    #endregion
  }
}

 

ARAddressExtension:

using PX.CS.Contracts.Interfaces;
using PX.Data.ReferentialIntegrity.Attributes;
using PX.Data;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects;
using System.Collections.Generic;
using System.Text;
using System;
using PX.Data.BQL.Fluent;

namespace PX.Objects.AR
{
  public class ARAddressExt : PXCacheExtension<PX.Objects.AR.ARAddress>
  {
    #region UsrAdressLine4
    bPXDBString(50)]
     PXUIField(DisplayName="Adresszeile 4")]
  
    public virtual string UsrAdressLine4 { get; set; }
    public abstract class usrAdressLine4 : PX.Data.BQL.BqlString.Field<usrAdressLine4> { }
    #endregion
  }
}

 

I already got to display these in the correct Screens for Customers, Vendors and Business Accounts, as well as Invoices (sales orders, shipments, purchase orders and bills are to come, as I get it to work with invoices).

I am now in need of a function to set the value from the Address UsrAdressLine4 into the ARAddress UsrAdressLine4 upon selection of a Customer on the Invoices and Memos screen.

It should work like the other standard AddressLine-Fields.

I tried a couple of darylbowmans Solutions from this thread.

I couldn’t get it to work with these Lines:

    nPXDefault(typeof(Search<AddressExt.usrAdressLine4,
            Where<Address.bAccountID, Equal<Current<ARInvoice.customerID>>>>))]
    4PXFormula(typeof(Default<ARInvoice.customerID>))]

nor

    ;PXDefault(typeof(SearchFor<AddressExt.usrAdressLine4>.
           In<SelectFrom<AddressExt>.
                   Where<Address.bAccountID.IsEqual<ARAddress.customerID>>>))]

 

Any ideas or pointers?

To pull a default value but allow users to change it, use this:

#region UsrAdressLine4
[PXDBString(50)]
[PXDefault(typeof(SearchFor<AddressExt.usrAdressLine4>.
In<SelectFrom<Address>.
Where<Address.bAccountID.IsEqual<ARAddress.customerID.FromCurrent>>>))]
//[PXFormula(typeof(Default<ARAddress.customerID>))]
[PXUIField(DisplayName="Adresszeile 4")]
public virtual string UsrAdressLine4 { get; set; }
public abstract class usrAdressLine4 : PX.Data.BQL.BqlString.Field<usrAdressLine4> { }
#endregion

Notice the bound [PXDBString] because the value is actually being saved in the database.

Also note that this will only default for NEW records. You can include a >PXFormula] to force the default to be recalculated when a particular value changes, like another field in the same DAC.

 

To pull a database value and populate an unbound field use this:

#region UsrCustomField
PXString]
PXDBScalar(typeof(SearchFor<BAccount.acctCD>.
In<SelectFrom<BAccount>.
Where<BAccount.bAccountID.IsEqual<CRCase.customerID>>>))]
PXUIField(DisplayName="Custom Field", Enabled = false)]
public virtual string UsrCustomField { get; set; }
public abstract class usrCustomField : PX.Data.BQL.BqlString.Field<usrCustomField> { }
#endregion

Notice the unbound dPXString]. Good practice here would be to include Enabled = false so the user doesn’t expect the value they enter will be saved (it won’t).


Thanks a lot Daryl! Your answer is spot on and it seems to work. I went with the bound version.

I still get some odd behavior though. It might have to do with the “Override Address” function and not with the custom field itself.

Whenever I have no value in the Fields origin (AddressExt.usrAdressLine4), I cant save the invoice and get the Error message “Error: 'Adresszeile 4' cannot be empty.”

The field should not be mandatory and the indicator for it to be mandatory cannot be seen with the exemption that it is visible, when the checkbox “Override Address” is checked.

I assume it has something to do with the override function, but I cannot locate it.
 

 


Fantastic.

Nope, it's actually the PXDefault. I didn't think about that. Use this instead:

[PXDefault(typeof(SearchFor<AddressExt.usrAdressLine4>.
    In<SelectFrom<Address>.
    Where<Address.bAccountID.IsEqual<ARAddress.customerID.FromCurrent>>>), PersistingCheck = PXPersistingCheck.Nothing)]

 


That’s it!

You were incredibly helpful, thanks a lot!


Sure thing 🙂


Reply