Skip to main content
Answer

Set a Default Value for a Selector?

  • February 11, 2025
  • 2 replies
  • 90 views

Forum|alt.badge.img

For one of our projects, we set a single value to be selected from a box. However the box is still defaulting to one of the old value that we removed. I’m trying to have it default to the constant defined below, but everything I’ve tried either hasn’t worked or crashed the customization. Any way to set a default value for this box?

public class custClass : PX.Data.BQL.BqlString.Constant<custClass>
{
public custClass() : base("SB") { }
}

[PXDBString(2, IsKey = true, IsFixed = true, InputMask=">aa")]


[PXDefault(SOOrderTypeConstants.SalesOrder, typeof(SOSetup.defaultOrderType))]
[PXSelector(typeof(Search2<SOOrderType.orderType,
InnerJoin<SOOrderTypeOperation, On2<SOOrderTypeOperation.FK.OrderType, And<SOOrderTypeOperation.operation, Equal<SOOrderType.defaultOperation>>>>,
Where<FeatureInstalled<FeaturesSet.inventory>.Or<SOOrderType.behavior.IsNotEqual<SOBehavior.bL>>>>))]

[PXRestrictor(typeof(Where<SOOrderTypeOperation.iNDocType, NotEqual<INTranType.transfer>, Or<FeatureInstalled<FeaturesSet.warehouse>>>), ErrorMessages.ElementDoesntExist, typeof(SOOrderType.orderType))]

[PXRestrictor(typeof(Where<SOOrderType.orderType, Equal<custClass>>),"" )]

[PXRestrictor(typeof(Where<SOOrderType.requireAllocation, NotEqual<True>, Or<AllocationAllowed>>), ErrorMessages.ElementDoesntExist, typeof(SOOrderType.orderType))]
[PXRestrictor(typeof(Where<SOOrderType.active,Equal<True>>), null)]
[PXUIField(DisplayName = "Order Type", Visibility = PXUIVisibility.SelectorVisible)]
[PX.Data.EP.PXFieldDescription]

 

Best answer by Django

The PXDefault attribute is used to provide a declarative way of defining a default value for the field when the record is inserted into the cache at the DAC level. 

You can override this default logic on a per screen basis by using _CacheAttached event declaration.

So, in your code above:

[PXDefault(SOOrderTypeConstants.SalesOrder, typeof(SOSetup.defaultOrderType))]

the PXDefault is causing the value to default to be “SO” unless SOSetup.defaultOrderType has a non-null value.

If you want the default to be SB, you can change that in SO Setup:

 

2 replies

Forum|alt.badge.img+7
  • Captain II
  • Answer
  • February 11, 2025

The PXDefault attribute is used to provide a declarative way of defining a default value for the field when the record is inserted into the cache at the DAC level. 

You can override this default logic on a per screen basis by using _CacheAttached event declaration.

So, in your code above:

[PXDefault(SOOrderTypeConstants.SalesOrder, typeof(SOSetup.defaultOrderType))]

the PXDefault is causing the value to default to be “SO” unless SOSetup.defaultOrderType has a non-null value.

If you want the default to be SB, you can change that in SO Setup:

 


Forum|alt.badge.img+1

Ensure PXDefault Uses your Custom Constant: the [PXDefault] attribute should use your custClass constant instead of SOOrderTypeConstants.SalesOrder.

Setting [PXDefault] for a Customization in Acumatica:
If you are working with Graph Extensions and DAC Extensions, here’s how to set a default value correctly for both.
1) Setting Default in a DAC Extension:

using PX.Data;
using PX.Data.BQL;

namespace Customization
{
public class SOOrderExt : PXCacheExtension<PX.Objects.SO.SOOrder>
{
public static bool IsActive() => true; // Ensures the extension is applied.

public class custClass : BqlString.Constant<custClass>
{
public custClass() : base("SB") { }
}

[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXDefault(typeof(custClass))] // Setting default value
public string OrderType { get; set; }
}
}

 

2) Setting Default Value in a Graph Extension:

using PX.Data;
using PX.Objects.SO;

namespace Customization
{
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
public class custClass : PX.Data.BQL.BqlString.Constant<custClass>
{
public custClass() : base("SB") { }
}

[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXDefault(typeof(custClass))] // Setting default value
protected virtual void SOOrder_OrderType_CacheAttached(PXCache sender) { }
}
}

You can also use an FieldDefaulting event handler to set the property to the default property needed
 

using PX.Data;
using PX.Objects.SO;

namespace Customization
{
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{


public class custClass : PX.Data.BQL.BqlString.Constant<custClass>
{
public custClass() : base("SB") { }
}
protected void SOOrder_OrderType_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
SOOrder row = (SOOrder)e.Row;
if (row == null) return;

...
e.NewValue = custClass;

}
}
}