How to make calculated field available in Generic Inquiry screen of Acumatica and Starship

Hello everybody,

today I want to describe interesting case. 

I was asked to add on Acumatica screen Date field, which calculates according to some business logic rules. Task was pretty simple initially to do, so I've jumped, and added that field like this:

public abstract class usrExpectedByDate : IBqlField
{
}
 
[PXDBDate()]
[PXUIField(DisplayName = "Expect Date", IsReadOnly = true)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
public virtual DateTime? UsrExpectedByDate { getset; }

I provided this customization to customer and had expectation that I can enjoy from my life. 

But with time, customer notified me, that shiping didn't work as expected. Why, because in program starship, which customer used Acumatica added some time information and starship wasn't able to get it properly.

I've decided to add formatting to Acumatica with help of InputMask attribute and DisplayMask attribute like this:

public abstract class usrExpectedByDate : IBqlField
{
}
 
[PXDBDate(InputMask = "MM/dd/yyyy", DisplayMask = "MM/dd/yyyy")]
[PXUIField(DisplayName = "Expected By Date", IsReadOnly = true)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
public virtual DateTime? UsrExpectedByDate { getset; }

But it didn't change outcome at all. On Acumatica screen it looked perfectly fine, but in import again looked with added hour, minute, second information. 

What programmers do in such cases? Exactly, add string, and add formatting to that string. Here is the string that I've added:

public abstract class usrExpectedByDate2 : IBqlField
{
}
 
[PXString]
[PXUIField(DisplayName = "Expected By Date", IsReadOnly = true)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
public virtual string UsrExpectedByDate2 {
    get
    {
        if (this.UsrExpectedByDate == null)
            return "";
        return this.UsrExpectedByDate.Value.ToString("MM/dd/yyyy");
    }
    set
    {
        if (value != null)
            this.UsrExpectedByDate = DateTime.Parse(value);
    }
}

That lead to chaning of situation. Instead of added zeros, field become empty. Just null. 

After wondering through source code of Acumatica, I found interesting attriubute: PXDependsOnField. After I've added that attribute, import worked fine. Here is final result:

public abstract class usrExpectedByDate2 : IBqlField
{
}
 
[PXString]
[PXUIField(DisplayName = "Expected By Date", IsReadOnly = true)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
public virtual string UsrExpectedByDate2 {
    [PXDependsOnFields(typeof(usrExpectedByDate))]
    get
    {
        if (this.UsrExpectedByDate == null)
            return "";
        return this.UsrExpectedByDate.Value.ToString("MM/dd/yyyy");
    }
    set
    {
        if (value != null)
            this.UsrExpectedByDate = DateTime.Parse(value);
    }
}

After those changes Starship support confirmed that information from my field become available on their end.

No Comments

Add a Comment