Skip to main content
Solved

How to Retrieve System Time on Form Save and Perform Calculations in Acumatica?

  • 25 July 2024
  • 5 replies
  • 70 views

Hi,

I have a requirement in Acumatica to retrieve the system time when a user saves a form for the first time. I need to use this system time to perform a calculation and update a field value on the same form. Is there a method to get the system time in Acumatica? If so, could you please provide detailed steps or guidelines on how to achieve this?

Thank you in advance for your assistance!

5 replies

Userlevel 4
Badge

@RKarunarathne51 

Just a clarifying question.

When you say “System Time”, are you referring to “Acumatica System” time, commonly referred to as “Business Date”, or are you wanting to retrieve the current UTC (Computer) time?

Userlevel 7
Badge +11

Hi @RKarunarathne51 ,

  • Creating a Custom Field in the DAC: Introduce a new field to store the system time when the form is saved.

  • Overriding the RowPersisting Event: Utilize the RowPersisting event to record the system time when saving the form for the initial instance.

  • Updating the Field Value: Apply the recorded system time for required calculations and field updates.

    Sample code:
     

     protected void YourDAC_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
    {
    var row = (YourDAC)e.Row;
    if (row == null) return;

    // Check if the record is being inserted
    if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Insert)
    {
    // Capture the current system time
    row.newField = PXTimeZoneInfo.Now;
    }
    }

     

Badge +12

Acumatica already stores the time when a record is created for most records. It’s called CreatedDateTime.

I’ve seen a couple of your recent questions and they are very general. If you want specific and applicable suggestions, we need some details about what you’re trying to accomplish. There is not a one-size fits all in Acumatica. The basic mechanisms of the platform are somewhat universal, but each screen is unique in how those mechanisms have been combined.

Userlevel 1
Badge

@MichaelShirk ,

I want to retrieve the current UTC (Computer) time. Thank you

Userlevel 6
Badge +2

Hi @RKarunarathne51 

var machineTime = DateTime.Now;
var machineTimeUtc = DateTime.UtcNow;
var instanceTime = PXTimeZoneInfo.Now;
var instanceTimeUtc = PXTimeZoneInfo.UtcNow;

Here are multiple options you can use to get the time depending on your use case.

Make sure you understand the difference between server (machine) time and instance (Acumatica) time. It isn’t exactly the same thing (for me they are different most of the time).

I’d also want to stress again what Daryl said before - we are creating Audit fields for that reason in DACs. If you are using your custom DAC, take a look at a standard one (most of Acumatica’s DACs have these audit fields). What you ask sounds exactly like CreatedDateTime.

If you use your custom DAC, I’d urge you to add the full set of audit fields, to avoid stumbling upon issues each time they are required, but not added.

Reply