Hello,
I'm tyring to use the Integration Bus to send new orders to an external ERP system.
My code looks like this:
public class ErpConnector : BaseIntegrationConnector
{
public override void Init()
{
ConnectorName = "ErpConnector";
SubscribeToObjects(TaskProcessTypeEnum.AsyncSnapshot, OrderInfo.OBJECT_TYPE);
}
public override IntegrationProcessResultEnum ProcessInternalTaskAsync(GeneralizedInfo infoObj,
TranslationHelper translations, TaskTypeEnum taskType, TaskDataTypeEnum dataType, string siteName,
out string errorMessage)
{
// Runs when processing Snapshot type tasks for order objects
if (infoObj.TypeInfo.ObjectType == OrderInfo.OBJECT_TYPE &&
dataType == TaskDataTypeEnum.Snapshot &&
taskType == TaskTypeEnum.CreateObject)
{
var orderInfo = (OrderInfo)(infoObj.MainObject);
...
}
}
}
I'm basically subscribing to changes to the OrderInfo object and execute my custom code if the taskType is CreateObject.
The problem is, when the OrderInfo object gets created, and my integration gets called, the addresses (Shipping or Billing) are sometimes null. It's a race condition. As far as I can tell from the Event Log, Kentico updates the order object one more time after creation. My guess is that Kentico creates the OrderInfo object first and adds the addresses later.
Here is a screenshot of the Event Log:
https://drive.google.com/file/d/1TUN-E9RYRyBSOzcg6a6lw479q5ZZYNyj/view?usp=sharing
You can see that the first run of the integration failed, because of the NullReference on the address field. It worked fine during the second try a few seconds later.
Is that a bug in Kentico or am I doing something wrong? I don't really want to listen to the UpdateObject event because we only want to send the data once on the first creation of an order but no updates.
I'm using Kentico 12.0.31.
Thanks,
Andy