acumaticaacumatica-kb

Is there a way to add User Defined fields to a custom screen?


I have several completely custom screens, and I've noticed that I can add User defined fields to standard screens, such as Projects:

enter image description here

However - this option is missing on my custom screen:

enter image description here

Is there an option on my custom screen's properties I can set to make this available - or is this just something that can't be done on a non-standard Acumatica screen?

Thanks...


Solution

  • It may not be recommended (yet), but the use of KvExt can be done:

    Related (much older) Question found here:

    [https://stackoverflow.com/questions/60096788/is-it-possible-to-create-my-own-custom-kvext-table-to-fully-implement-and-manage]

    1. Ensure the EnableAttributes flag is set to true in the ASPX DataSource tag near top of your page:

      <px:PXDataSource EnableAttributes="true"  ...  
      
    2. Create a "KvExt" table in SQL Server similar to your PrimaryView of your page:

      CREATE TABLE [dbo].[YourMasterDACKvExt](
      [CompanyID] [int] NOT NULL,
      [RecordID] [uniqueidentifier] NOT NULL,
      [FieldName] [varchar](50) NOT NULL,
      [ValueNumeric] [decimal](28, 8) NULL,
      [ValueDate] [datetime] NULL,
      [ValueString] [nvarchar](256) NULL,
      [ValueText] [nvarchar](max) NULL,
       CONSTRAINT [YourMasterDACKvExt_PK] PRIMARY KEY CLUSTERED 
      (
          [CompanyID] ASC,
          [RecordID] ASC,
          [FieldName] ASC
      )) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
      GO
      
      ALTER TABLE [dbo].[YourMasterDACKvExt] ADD  DEFAULT ((0)) FOR [CompanyID]
      GO
      
    3. Add code to create a DAC for the new table:

      [Serializable]
      [PXCacheName("YourMasterDACKvExt")]
      public class YourMasterDACKvExt : IBqlTable
      {
          #region Keys
          public class PK : PrimaryKeyOf<YourMasterDACKvExt>.By<recordID, fieldName>
          {
              public static YourMasterDACKvExt Find(PXGraph graph, int? recordID, string fieldName) =>
                                          FindBy(graph, recordID, fieldName);
          }
          #endregion
      
          public abstract class recordID : BqlGuid.Field<recordID> { }
          [PXDBGuid(IsKey = true)]
          [PXDBDefault(typeof(YourMasterDAC.noteID))]
          [PXParent(typeof(SelectFrom<YourMasterDAC>
              .Where<YourMasterDAC.noteID
              .IsEqual<YourMasterDACKvExt.record.FromCurrent>>))]
          public Guid? RecordID { get; set; }
      
          public abstract class fieldName : BqlString.Field<fieldName> { }
          [PXDBString(50, IsKey = true)]
          [PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
          [PXSelector(typeof(SearchFor<CS.CSAttribute.attributeID>
              .In<SelectFrom<CS.CSAttribute>>),
              DescriptionField = typeof(CS.CSAttribute.attributeID),
              SubstituteKey = typeof(CS.CSAttribute.attributeID),
              CacheGlobal = true)]
          [PXUIField(DisplayName = "Field Name")]
          public string FieldName
          {
              get;
              set;
          }
      
          public abstract class valueNumeric : BqlDecimal.Field<valueNumeric> { }
          [PXDBDecimal(8)]
          [PXUIField(DisplayName = "Value Numeric")]
          public virtual decimal? ValueNumeric { get; set; }
      
          public abstract class valueDate : BqlDateTime.Field<valueDate> { }
          [PXDBDate]
          [PXUIField(DisplayName = "Value Date")]
          public virtual DateTime? ValueDate { get; set; }
      
          public abstract class valueString : BqlString.Field<valueString> { }
          [PXDBString(50)]
          [PXUIField(DisplayName = "Value String")]
          public virtual string ValueString { get; set; }
      
          public abstract class valueText : BqlString.Field<valueText> { }
          [PXDBString]
          [PXUIField(DisplayName = "Value Text")]
          public virtual string ValueText { get; set; }
      }
      
    4. Ensure YourMasterDAC has a NoteID field:

          [PXNote]
          public virtual Guid? NoteID { get; set; }
      
          public abstract class noteID : BqlType<IBqlGuid, Guid>.Field<noteID>
          {
          }
      

    I was able to add multiple UDF fields to my custom page (version 23.211.0017) having the CheckBox style input and the KvExt answers stored correctly in the database (unlike the older link above).