1

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();
}
  • 1
    Two suggestions off the top of my head: * Check if the user who created the field (CreatedBy) is the Business Connector user. http://msdn.microsoft.com/en-us/library/aa871620.aspx * Create a new boolean field in CustTable and modify the AX class to always write a 'true' to that field. http://technet.microsoft.com/en-us/library/bb496530.aspx
    – ian_scho Nov 10 '14 at 08:18
  • AIF does impersonation though depending on settings, so the CreatedBy might not work. – Alex Kwitny Dec 01 '14 at 23:04

1 Answers1

1

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
}
Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71