Skip to main content
Answer

Condition of Interdependent Fields

  • April 1, 2025
  • 2 replies
  • 37 views

Hi I have two field StartDate and EndDate which are of type DATETIME in my Customization project.
Now want to add the codindtion in which start date and end date are independent on each other.

Conditions are :--
Cond 1 → EndDate > Start Date  → If the Start Date is selected first

Cond 2 → Start Date < End Date → If the End Date is selected first

My DAC fields are the below fields

#region StartDate
[PXDBDate()]
[PXUIField(DisplayName = "Start Date")]
public virtual DateTime? StartDate { get; set; }
public abstract class startDate : PX.Data.BQL.BqlDateTime.Field<startDate> { }
#endregion

#region EndDate
[PXDBDate()]
[PXUIField(DisplayName = "End Date")]
public virtual DateTime? EndDate { get; set; }
public abstract class endDate : PX.Data.BQL.BqlDateTime.Field<endDate> { }
#endregion

Best answer by svwk05

@anupusefulbi 

Use a FieldVerifying event in your graph extension to ensure EndDate is always greater than StartDate when either field is changed

Try below sample code

public class YourGraphExtension : PXGraphExtension<YourGraph>
{
protected void _(Events.FieldVerifying<YourDAC.startDate> e)
{
var row = (YourDAC)e.Row;
if (row == null || e.NewValue == null) return;

DateTime? newStartDate = (DateTime?)e.NewValue;

// Condition 1: If EndDate is already selected, StartDate must be less than EndDate
if (row.EndDate != null && newStartDate >= row.EndDate)
{
throw new PXSetPropertyException("Start Date must be earlier than End Date.");
}
}

protected void _(Events.FieldVerifying<YourDAC.endDate> e)
{
var row = (YourDAC)e.Row;
if (row == null || e.NewValue == null) return;

DateTime? newEndDate = (DateTime?)e.NewValue;

// Condition 2: If StartDate is already selected, EndDate must be greater than StartDate
if (row.StartDate != null && newEndDate <= row.StartDate)
{
throw new PXSetPropertyException("End Date must be later than Start Date.");
}
}
}

 

2 replies

Forum|alt.badge.img+1
  • Semi-Pro III
  • Answer
  • April 1, 2025

@anupusefulbi 

Use a FieldVerifying event in your graph extension to ensure EndDate is always greater than StartDate when either field is changed

Try below sample code

public class YourGraphExtension : PXGraphExtension<YourGraph>
{
protected void _(Events.FieldVerifying<YourDAC.startDate> e)
{
var row = (YourDAC)e.Row;
if (row == null || e.NewValue == null) return;

DateTime? newStartDate = (DateTime?)e.NewValue;

// Condition 1: If EndDate is already selected, StartDate must be less than EndDate
if (row.EndDate != null && newStartDate >= row.EndDate)
{
throw new PXSetPropertyException("Start Date must be earlier than End Date.");
}
}

protected void _(Events.FieldVerifying<YourDAC.endDate> e)
{
var row = (YourDAC)e.Row;
if (row == null || e.NewValue == null) return;

DateTime? newEndDate = (DateTime?)e.NewValue;

// Condition 2: If StartDate is already selected, EndDate must be greater than StartDate
if (row.StartDate != null && newEndDate <= row.StartDate)
{
throw new PXSetPropertyException("End Date must be later than Start Date.");
}
}
}

 


  • Author
  • Freshman I
  • April 1, 2025

Thank You Saikrishna V