Skip to main content
Solved

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


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.

Best answer by Hughes Beausejour

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
Did this topic help you find an answer to your question?

5 replies

Forum|alt.badge.img+5
  • Captain II
  • 505 replies
  • April 26, 2021

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?


  • Author
  • Freshman I
  • 6 replies
  • April 26, 2021

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.


Hughes Beausejour
Acumatica Employee
Forum|alt.badge.img+2
  • Acumatica Developer Support Team
  • 91 replies
  • Answer
  • April 26, 2021

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";
    }
}


  • Author
  • Freshman I
  • 6 replies
  • April 28, 2021

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.


Hughes Beausejour
Acumatica Employee
Forum|alt.badge.img+2
  • Acumatica Developer Support Team
  • 91 replies
  • April 29, 2021

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings