Michael Wang
Michael Wang

Reputation: 5

Acumatica: How to set default shipment date as tomorrow

[PXDefault(typeof(AccessInfo.businessDate))] can be used to set default date.But, can I have a way to set the date as businessdate+1? I don't know how to operate the dates. Can anybody help me?

Upvotes: 0

Views: 1009

Answers (2)

Brendan
Brendan

Reputation: 5623

An alternative to @KRichardson answer if you dont want to set graph events. More so if you use the DAC in mulitple graphs creating your own attribute would work. Here is a working example of an Attribute:

public class CurrentDateDefaultAttribute : PXDefaultAttribute
{
    protected int AddDays;

    public CurrentDateDefaultAttribute() : this(0)
    {
    }

    public CurrentDateDefaultAttribute(int addDays)
    {
        AddDays = addDays;
    }

    public override void FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
    {
        e.NewValue = sender.Graph.Accessinfo.BusinessDate.GetValueOrDefault().AddDays(AddDays);
    }
}

Then you would use the attribute in your DAC on your Date field as shown below. Enter in the AddDays property to shift the current date value:

[PXDBDate]
[CurrentDateDefault(1)]
[PXUIField(DisplayName = "My Date")]
public virtual DateTime? MyDate { get; set; }

Upvotes: 4

KRichardson
KRichardson

Reputation: 1010

Try setting the FieldDefaulting event on the graph to pull the business date and add to it. Here is an example that I tested in one of my customization projects:

protected virtual void CYHistoryDoc_DocDate_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
    e.NewValue = ((DateTime)Accessinfo.BusinessDate).AddDays(1);
}

Upvotes: 2

Related Questions