Overriding Attributes of a DAC field in the Graph

You can override one attribute or multiple attributes of a DAC field for a particular screen without changing the existing behavior of the attribute or attributes for all other screens.

You can do the following to override the attributes of a DAC field:
  • Replace the whole set of attributes
  • Append an attribute
  • Override a single property of an attribute
  • Replace one attribute with another

To override attributes, you should declare a CacheAttached event handler in the graph that corresponds to the screen for which you want to change the DAC field's behavior. With the declared CacheAttached event handler, you use special attributes, depending on what you want to do with the original attributes, as described in the following sections.

Replacing the Whole Set of Attributes

To override all attributes at once, you should only declare a CacheAttached event handler in the graph.

Suppose that the original DAC field attributes are declared as shown in the following code.
public class ARInvoice : IBqlTable
{    
    [PXDBDecimal(4)]    
    [PXDefault(TypeCode.Decimal, "0.0")]    
    [PXUIField(DisplayName = "Commission amount")]    
    public virtual Decimal? CommAmt     
    {         
        get;         
        set;     
    }
}

To override a DAC field by using the CacheAttached event handler, in the graph corresponding to the screen whose behavior you want to change, declare the CacheAttached event handler for the field. The event handler must be named according to the standard conventions for naming graph events that is described in the Event Handlers topic.

For the CommAmt field, the code for the event handler looks like the following.
[PXDBDecimal(4)]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Commission Amount")]
[PXAdditionalAttribute(NecessaryProperty = true)]
protected virtual void ARInvoice_CommAmt_CacheAttached(PXCache sender) { }

In this example, we added the PXAdditionalAttribute to the list of the CommAmt field attributes.

The set of attributes on the CacheAttached handler redefines the whole set of attributes placed on the specified DAC field. This results in undesired copying of all unmodified attributes, and the DAC and the graph no longer act synchronously. Therefore, we do not recommend using this method unless you intend to override all attributes of a field.

Appending an Attribute

MYOB Advanced Framework provides a special attribute called PXMergeAttributesAttribute. When placed on a CacheAttached event handler for the corresponding DAC field, this attribute allows gives you the ability to reuse the existing attributes of a DAC field.

To append an attribute, you declare the CacheAttached event handler with the PXMergeAttributes attribute and the new attribute (or attributes), as shown in the following code.

[PXMergeAttributes(Method = MergeMethod.Append)]
[PXAdditionalAttribute(NecessaryProperty = true)]
protected virtual void ARInvoice_CommAmt_CacheAttached(PXCache sender) { }

This example works similarly to the previous one: It adds the PXAdditionalAttribute attribute to the list of the CommAmt field attributes, but without code duplication.

Overriding a Single Property of an Attribute

MYOB Advanced Framework provides a special attribute called PXCustomizeBaseAttribute. When placed on a CacheAttached event handler for the corresponding DAC field, this attribute gives you the ability to redefine a single property of an attribute.

For example, suppose that you need to change the UI display name from Commission Amount to Base Currency Commission for only one screen. The code should look like the following.

[PXMergeAttributes(Method = MergeMethod.Append)]
[PXCustomizeBaseAttribute(typeof(PXUIField), 
  nameof(PXUIFieldAttribute.DisplayName), "Base Currency Commission")]
protected virtual void ARInvoice_CommAmt_CacheAttached(PXCache sender) { }

This example reuses the existing attributes by using the PXMergeAttributes attribute and redefines the PXUIFieldAttribute attribute by using the PXCustomizeBaseAttribute attribute.

Replacing One Attribute with Another

MYOB Advanced Framework provides a special attribute called PXRemoveBaseAttribute. When placed on a CacheAttached event handler for the corresponding DAC field, this attribute gives you the ability to remove the specified attribute.

For example, suppose that you need to replace PXDefaultAttribute with PXDBDefaultAttribute for only one screen. Further suppose that the original field declaration looks the one shown in the following code.

[Site(DisplayName = "Warehouse ID", 
  DescriptionField = typeof(INSite.descr))]
[PXDefault(typeof(SOShipment.siteID), 
  PersistingCheck = PXPersistingCheck.Nothing)]
public virtual Int32? SiteID { get; set; }

Then replacing PXDefaultAttribute with PXDBDefaultAttribute looks as shown in the following code.

[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRemoveBaseAttribute(typeof(PXDefaultAttribute))]
[PXDBDefault(typeof(SOShipment.siteID), 
  PersistingCheck = PXPersistingCheck.Nothing)]
protected void SOOrderShipment_SiteID_CacheAttached(PXCache sender) { }

In this example, all existing attributes are reused by the PXMergeAttributes attribute, the PXDefaultAttribute is removed by the PXRemoveBaseAttribute attribute, and the new PXDBDefault attribute is declared.

Application Order of the Custom Attributes

The customization attributes described above are applied in the following order:

  1. PXCustomizeBaseAttribute
  2. PXRemoveBaseAttribute
  3. PXMergeAttributes