Bojensen Blogs

Create/Delete Customer using AIF Service Class in Dynamics AX | Santosh Ramamurthy AX Blog

 

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.

Create/Delete Customer using AIF Service Class in Dynamics AX | Santosh Ramamurthy AX Blog

Comments are closed.