Solved

How to change default value for a field on a form?

  • 26 April 2021
  • 5 replies
  • 81 views

Hello all,

 

How would I go about changing the default value in the customization project for a specific field on a form?

 

 

I though it would be under this section, but I haven’t had any luck so far.

icon

Best answer by Hughes Beausejour 26 April 2021, 22:12

Override the target field and change PXDefault attribute:
        #region CaseClassID
        public abstract class caseClassID : PX.Data.BQL.BqlString.Field<caseClassID> { }

        [PXDBString(10, IsUnicode = true, InputMask = ">aaaaaaaaaa")]
        [PXDefault(typeof(Search<CRSetup.defaultCaseClassID>))]
        [PXUIField(DisplayName = "Class ID")]
        [PXSelector(typeof(CRCaseClass.caseClassID), 
            DescriptionField = typeof(CRCaseClass.description), 
            CacheGlobal = true)]
        [PXMassUpdatableField]
        public virtual String CaseClassID { get; set; }
        #endregion

Or create a graph extension, then use FieldDefaulting event and NewValue property:
public class CRCaseMaintExt : PXGraphExtension<PX.Objects.CR.CRCaseMaint>
{
    public virtual void CRCase_CaseClassID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
    {
        e.NewValue = "DefaultValue";
    }
}

View original

5 replies

Userlevel 1
Badge

Typically you won’t change the business logic for default field values within the screen code.  What are you trying to do with your change?

Hi ddunn,

I am trying to use the case class id as a unique identifier for cases, therefore i have setup different forms and views in case management to segregate let’s say between customer service and construction department. I need to change default values for those screens individually so that users dont have to every time they manually enter a case.

 

Example: customer service employee opens their case management form and “CS” is already checked by default and they cannot update. This way their cases stay in their section

 

Hopefully that made sense.

Userlevel 4

Override the target field and change PXDefault attribute:
        #region CaseClassID
        public abstract class caseClassID : PX.Data.BQL.BqlString.Field<caseClassID> { }

        [PXDBString(10, IsUnicode = true, InputMask = ">aaaaaaaaaa")]
        [PXDefault(typeof(Search<CRSetup.defaultCaseClassID>))]
        [PXUIField(DisplayName = "Class ID")]
        [PXSelector(typeof(CRCaseClass.caseClassID), 
            DescriptionField = typeof(CRCaseClass.description), 
            CacheGlobal = true)]
        [PXMassUpdatableField]
        public virtual String CaseClassID { get; set; }
        #endregion

Or create a graph extension, then use FieldDefaulting event and NewValue property:
public class CRCaseMaintExt : PXGraphExtension<PX.Objects.CR.CRCaseMaint>
{
    public virtual void CRCase_CaseClassID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
    {
        e.NewValue = "DefaultValue";
    }
}

Thanks Hughes, looks like that 1st option might be the way.

 

Would you happen to know the syntax to default it to a specific Class ID? I’m kind of lost on that part.

Userlevel 4

PXDefault attribute points to DB field CRSetup.defaultCaseClassID. This is where the default value is stored. In UI this field is shown in Customer Management Preferences screen:
 

If you need any complex initialization logic PXDefault attribute will not be able to do it. You need to use FieldDefaulting or build a custom defaulting attribute for that.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2020  Acumatica, Inc. All rights reserved