Thursday, May 16, 2013

AX 2012 AIF - How to create outbound AIF record through X++

When you want to create a record in the outbound AIF queue in AX 2012, you can use the below code to accomplish this.  It can be included in inserts, updates, on a button, etc. Doesn't really matter.

There are two variables below:
  • YYYTable - This should be the instance record of a table. For example, if you create a new vendor, customer purchase order, etc, you can put the record instance in this spot (for instance, in the insert override, after the super() you can use 'this').
  • YYYService - The name of the service that is being use
In order for this to work, you will need to setup an outbound port and run the AIF process with the for various processes. Until this last process is complete, this record will remain in the AIF queue.

AxdSendContext      axdSendContext      = AxdSendContext::construct();
AifEntityKey        aifEntityKey        = AifEntityKey::construct();
Map                 keyData;
AifConstraintList   aifConstraintList   = new AifConstraintList();
AifConstraint       aifConstraint       = new AifConstraint();

// Select key data
keyData = SysDictTable::getKeyData(YYYTable); // 'this' is the internal instance of ZZZTestAIF so we can use this
aifEntityKey.parmKeyDataMap(keyData);

// Select context as original
axdSendContext.parmXMLDocPurpose(XMLDocPurpose::Original);
axdSendContext.parmSecurity(false);

// No constraints
aifConstraint.parmType(AifConstraintType::NoConstraint) ;
aifConstraintList.addConstraint(aifConstraint) ;

// Initiate AIF Portal vendor service
AifSendService::submitDefault(classnum(YYYService), // Assign the service here
                              aifEntityKey,
                              aifConstraintList,
                              AifSendMode::Sync,
                              axdSendContext.pack());

No comments:

Post a Comment