AX 2012: Trigger AIF Document Service Outbound Message in X++

Posted on Updated on

Purpose:

The purpose of this document is to illustrate how we can trigger the generation of AIF document service outbound message in X++.

Business requirement:

Ability to generate an AIF outbound xml message on demand.

Assumptions:

Outbound port is configured using file system adapter.

Development:

Please find the job below to trigger an AIF document service outbound message in X++. The job uses the standard CustCustomerService class to generate outbound xml for customer data. Likewise the code can be used for any other valid document service class.

// Developed on 18 Feb 2016 by Muhammad Anas Khan
// Blog: dynamicsaxinsight.wordpress.com
// LinkedIn: pk.linkedin.com/in/muhammadanaskhan
// Description: Trigger AIF document service outbound message
static void sendElectronically(
    XMLDocPurpose _xMLDocPurpose,
    AifSendMode   _aifSendMode = AifSendMode::Async)
{
    AxdSendContext    axdSendContext = AxdSendContext::construct();
    AifEntityKey      aifEntityKey = AifEntityKey::construct();
    AifConstraintList aifConstraintList = new AifConstraintList();
    AifConstraint     aifConstraint = new AifConstraint();
    CustTable         custTable;
    Map               keyData;
    
    custTable = CustTable::find("1101");
    
    keyData = SysDictTable::getKeyData(custTable);
    aifEntityKey.parmTableId(custTable.TableId);
    aifEntityKey.parmRecId(custTable.RecId);
    aifEntityKey.parmKeyDataMap(keyData);
    axdSendContext.parmXMLDocPurpose(_xMLDocPurpose);
    axdSendContext.parmSecurity(false);
    aifConstraint.parmType(AifConstraintType::NoConstraint);
    
    aifConstraintList.addConstraint(aifConstraint);
    AifSendService::submitDefault(
        classnum(CustCustomerService),  //Service class goes here
        aifEntityKey,
        aifConstraintList,
        _aifSendMode,
        axdSendContext.pack());
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s