Skip to main content

It is standard practice for systems to communicate date/times converted to UTC. You do not know if the system you are integrating with potentially is in a different time zone. Acumatica handles this conversion under the hood for you, and you don’t have to deal with it. There can be a problem however when you integrate with a system that does not follow this practice. I am going to show you how to set the current timezone in the system within the context of a webhook, where you might be receiving datetimes in multiple different timezones from multiple different systems.

Acumatica webhooks are processed in a user contextless system, and you need to initialize the context when processing them. From Yuriy Zaletskyy’s blog post on how to write Webhook handlers, I then extended the “GetAdminScope()” method:

private IDisposable GetAdminScope()
{
var userName = "admin";
if (PXDatabase.Companies.Length > 0)
{
var company = PXAccess.GetCompanyName();
if (string.IsNullOrEmpty(company))
{
company = PXDatabase.CompaniesC0];
}
userName = userName + "@" + company;
}
LocaleInfo.SetTimeZone(PXTimeZoneInfo.FindSystemTimeZoneById("GMTM0800A"));
return new PXLoginScope(userName);
}

// And then inside your webhook handler:
using var adminScope = GetAdminScope();

The two critical methods are:

var timeZoneInfo = PXTimeZoneInfo.FindSystemTimeZoneById("Your Time Zone Code");
LocaleInfo.SetTimeZone(timeZoneInfo);

// You can find all the timezone codes in the PXTimeZoneInfo class.


Now, we are setting a special Time Zone for processing this webhook request. Acumatica will then transfer the datetimes correctly and store them in the database correctly converted to UTC.

I hope that perhaps this post was helpful in reducing headaches with one of your integrations. 

Thank you for sharing this with the community @Kyle Vanderstoep!


Reply