Question

Display/set default date on date field from form creation where the field is from the other custom table.

  • 17 September 2023
  • 2 replies
  • 127 views

Userlevel 1

Hi Everyone,

 

I’m currently customizing the ProjectEntry graph where I added a custom table to the tab. In my custom table, I have defined a date field, where I declared a default date [PXDefault(typeof(AccessInfo.businessDate))], but when I create a new empty project, I want to fill the date field with current date. Can anyone help me how to implement this?

 

#Custom field from a custom table

#region IBqlTable
    [PXDefault(typeof(AccessInfo.businessDate))]
    [PXDBDate()]
    [PXUIField(DisplayName = "Date MOB Promised", Required = true)]
    public virtual DateTime? DateMobPromised { get; set; }
    public abstract class dateMobPromised : PX.Data.BQL.BqlDateTime.Field<dateMobPromised> { }
 #endregion

 

#region Data View

public SelectFrom<ProjectCustomFields>.
            Where<ProjectCustomFields.contractID.IsEqual<PMProject.contractID.FromCurrent>>.View MyProjectCustomFields;

#endregion

 

I have tried to override the Initialize method but still no luck.

public PXSelect<ProjectCustomFields> MyProjectCustomFields;

        public override void Initialize()
        {

            base.Initialize();

            ProjectCustomFields anotherRecord = new ProjectCustomFields();

            anotherRecord.ToBeReleased = DateTime.Now;

            // Acuminator disable once PX1059 ChangesInPXCacheDuringPXGraphInitialization [Justification]
            MyProjectCustomFields.Insert(anotherRecord);

        }

 

It is very much appreciated if you can help me.

Thank you


2 replies

Badge +11

I'm a little confused. Your field definition example is for DateMobPromised but in your code, you're setting the value of anotherRecord.ToBeReleased. Which field are you trying to default?

Userlevel 1

I'm a little confused. Your field definition example is for DateMobPromised but in your code, you're setting the value of anotherRecord.ToBeReleased. Which field are you trying to default?

I apologize for the mistake; I’ll post the code again:

Custom Table

public class PSBSITermsAndPayment : IBqlTable
{
#region ContractID
[PXDBInt(IsKey = true)]
[PXDBDefault(typeof(PMProject.contractID))]
[PXParent(typeof(SelectFrom<PMProject>
.Where<PMProject.contractID.IsEqual<PSBSITermsAndPayment.contractID.FromCurrent>>))]
public virtual int? ContractID { get; set; }
public abstract class contractID : PX.Data.BQL.BqlInt.Field<contractID> { }
#endregion



#region ToBeReleased
[PXDefault(typeof(AccessInfo.businessDate))]
[PXDBDate()]
[PXUIField(DisplayName = "To Be Released On", Required = true)]
public virtual DateTime? ToBeReleased { get; set; }
public abstract class toBeReleased : PX.Data.BQL.BqlDateTime.Field<toBeReleased> { }
#endregion
}

 

Data View

 

 public class ProjectEntry_Extension : PXGraphExtension<ProjectEntry>
{

#region DataViews

public SelectFrom<PSBSITermsAndPayment>.
Where<PSBSITermsAndPayment.contractID.IsEqual<PMProject.contractID.FromCurrent>>.View TermsAndPayment;

}

Override Initialize

 

public override void Initialize()
{
base.Initialize();
PSBSITermsAndPayment anotherRecord = new PSBSITermsAndPayment();
anotherRecord.ToBeReleased = DateTime.Now;
// Acuminator disable once PX1059 ChangesInPXCacheDuringPXGraphInitialization [Justification]
TermsAndPayment.Insert(anotherRecord);
}

 

Layout 

 <px:PXFormView runat="server" ID="PSBSI_TermsAndPayment" DataMember="TermsAndPayment" Caption="Terms And Payment" RenderStyle="Fieldset">
<Template>
<px:PXLayoutRule runat="server" ID="CstPXLayoutRule21" StartColumn="True" ControlSize="XXL" LabelsWidth="SM" />
<px:PXLayoutRule runat="server" ID="CstPXLayoutRule111" Merge="True" />
<px:PXNumberEdit runat="server" ID="PSBSI_DownPayment" DataField="DownPayment" />
<px:PXCheckBox runat="server" ID="PSBSI_IsDownPayment" DataField="IsDownPayment" />
<px:PXLayoutRule runat="server" ID="CstPXLayoutRule110" Merge="True" />
<px:PXNumberEdit runat="server" ID="PSBSI_ProgressBilling" DataField="ProgressBilling" />
<px:PXCheckBox runat="server" ID="PSBSI_IsProgressBilling" DataField="IsProgressBilling" />
<px:PXLayoutRule runat="server" ID="CstPXLayoutRule109" Merge="True" />
<px:PXNumberEdit runat="server" ID="PSBSI_UponCompletion" DataField="UponCompletion" />
<px:PXCheckBox runat="server" ID="PSBSI_IsUponCompletion" DataField="IsUponCompletion" />
<px:PXLayoutRule runat="server" ID="CstPXLayoutRule108" StartGroup="True" />
<px:PXDateTimeEdit runat="server" ID="PSBSI_ToBeReleased" DataField="ToBeReleased">
<AutoCallBack>
<Behavior CommitChanges="True" /></AutoCallBack></px:PXDateTimeEdit>
<px:PXTextEdit runat="server" ID="PSBSI_Remarks" DataField="Remarks" /></Template></px:PXFormView>

 

Thank you

 

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 — 2024  Acumatica, Inc. All rights reserved