Reputation: 55
I have a customer-sync built that syncs AX customers with an external system's customers.
When an update/insert is performed on the external system, it dumps an AIF file that gets processed.
I want to put some logic in the table method CustTable.insert()
and CustTable.update()
so that when anything is inserted/updated it will push up the the external system, which works fine.
The problem is when a user makes a change in the external system, it makes the AIF file, which then inserts/updates in AX, then pushes a change back up to the external system.
How can I determine when a custTable insert/update is being performed from an AIF process? Pseudo code I'm looking for would be like this in the Tables\CustTable\Methods\insert()
:
// Pseudo code
if (this.isFromAIF() == false)
{
this.syncRecordToExternalSystem();
}
Upvotes: 1
Views: 2471
Reputation: 11544
This is a very difficult question. As @ian_socho said you can create a custom flag that only the AIF sets. The "createdby" user wouldn't work because the AIF does impersonation.
I did experiment and found some interesting properties. It seems like AIF operations execute in the CIL as a worker thread, but the worker thread seems to be spun up by the AOS, so there is no masterSessionId
that I can tell.
This code will tell you if something has maybe been called from the AIF. I tested with SysOpFramework that spins up worker threads, and they all have a master thread. I tested with a visual studio project and it has a master session.
xSession xSession = new xSession(sessionId());
if (xSession.masterSessionId() == 0 &&
xSession.isWorkerThread() == true &&
xSession.clientKind() == ClientType::WorkerThread)
{
// Appears to have been called from AIF
return true; // AIF call
}
Upvotes: 1