Home > X++ stuffs > Create/Delete Customer using AIF Service Class in Dynamics AX

Create/Delete Customer using AIF Service Class in Dynamics AX

 

The Application Integration Framework allows us to create/update/delete or read data. Now in AX2009 we have a facility of creating/deleting records using AIF Service classes. There is "NO ADDITIONAL AIF SETUP"(Like Enabling Endpoints etc.) required to execute the code via service class. The services can be used to read/write data in AX.

X++ service class job is illustrated below. 

static void Services_CustTable_Create(Args _args)

{

    // Customer Service class

    CustCustomerService     custService;

    CustCustomer                customer;

 

    // Data object of Service class

    CustCustomer_CustTable  custTable;

    AifEntityKeyList               entityKeyList;

    AccountNum                    accountNum;

    ;

 

    //Service instance

    custService =  CustCustomerService::construct();

 

    customer = new CustCustomer();

    customer.createCustTable();

    custTable = customer.parmCustTable().addNew();

 

    custTable.parmName("Cust_Service");

    custTable.parmCustGroup("20");

    custTable.parmCurrency("EUR");

    custTable.parmPartyType(DirPartyType::Organization);

 

    // Create Customer

    entityKeyList = custService.create(customer);

 

    if(entityKeyList)

        accountNum = entityKeyList.getEntityKey(1).parmKeyDataMap().lookup(fieldnum(CustTable, AccountNum));

        infolog.messageWin().addLine(accountNum);

}

 

static void Services_CustTable_Delete(Args _args)

{

    AifEntityKeyList          entityKeyList;

    AifEntityKey               aifEntityKey;

   

    // Data object of Service class

    CustCustomerService     custService;

    CustTable                     custTable;

    ;

 

    aifEntityKey  = new AifEntityKey();

    entityKeyList = new AifEntityKeyList();

    custService   = CustCustomerService::construct();

 

    select firstonly custTable

        where custTable.Name == "Cust_Service";

 

    aifEntityKey.parmKeyDataMap(SysDictTable::getKeyData(custTable));

    entityKeyList.addEntityKey(aifEntityKey);

 

    try

    {

        // Delete Customer

        custService.delete(entityKeyList);

        info ("CustTable record was successfully deleted.");

    }

    catch(Exception::Error)

    {

        exceptionTextFallThrough();

    }

}

SO Creation:

 

static void Services_SO_Create(Args _args)

{

    // Sales Order Service class

    SalesSalesOrderService     salesService;

    SalesSalesOrder                salesOrder;

 

    // Data object of Service class

    SalesSalesOrder_SalesTable  salesTable;

    SalesSalesOrder_SalesLine    salesLine;

    AifEntityKeyList                   entityKeyList;

 

    SalesId                                salesId;

    ;

 

    //Service instance

    salesService =  SalesSalesOrderService::construct();

 

    salesOrder = new SalesSalesOrder();

    salesOrder.createSalesTable();

    salesTable = salesOrder.parmSalesTable().addNew();

    salesLine   = salesTable.createSalesLine().addNew();

 

    // Mandatory data filled for SalesTable

    salesTable.parmCustAccount("4000");

    salesTable.parmDeliveryDate(today());

    salesTable.parmPurchOrderFormNum(‘Test’);

 

    // Mandatory data filled

    salesLine.parmItemId(‘B-R14’);

    salesLine.parmSalesQty(1);

    salesLine.parmSalesUnit(‘Pcs’);

 

    // Create Sales Order

    entityKeyList = salesService.create(salesOrder);

    if(entityKeyList)

        salesId = entityKeyList.getEntityKey(1).parmKeyDataMap().lookup(fieldnum(SalesTable, SalesId));

        infolog.messageWin().addLine(salesId);

}

So services could be used directly to invoke any AIF operation. hAPPy Dax-BinggggggSmile

Advertisements
Categories: X++ stuffs
  1. Søren
    November 25, 2009 at 9:07 pm

    Thanks – that is exact what i needed for testing an integration without sending data through biztalk first.

  2. Anitha
    November 17, 2009 at 3:58 pm

    Another addition about SO.. Thnx… 🙂 u r gud in R&D Mr.AIF Fan..

  3. Santosh.
    November 16, 2009 at 5:39 pm

    Hey thanks yaar!!! Nope 🙂 I\’m not a AIF master. So was this useful in your prj requirement.

  4. Anitha
    November 16, 2009 at 5:35 pm

    Another useful info about AIF from AIF master :)Thnkx… Ur Entries play a major role in my pjt works .. 🙂

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

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

%d bloggers like this: