AIF testing in AX 2012

Continue reading

There are a couple of ways to test AIF inbound classes in Dynamics AX:

  1. From inside Dynamics AX using jobs:
    a. Testing only classes for creating records in database.
    b. Testing service classes and classes for creating records in database.
  2. Configuring and testing AIF service.

Testing only classes for creating records in database

Below is code for creating record in ProjTable.

static void ANG_AIF_TestServiceAX_1(Args _args)

{

  AifEntityKeyList                            entityKeyList;                          // Entity key list

  ProjTableService                            projTableService;                       // Service class

  ProjProjTable                               projProjTable;                          // Document object

  ProjProjTable_ProjTable                     projProjTable_ProjTable;                // data object;

  ProjProjTable_TableDlvAddr                  projProjTable_TableDlvAddr;             // data object

  // Create the service instance

  projTableService = ProjTableService::construct();

  // Create the data document object

  projProjTable = new ProjProjTable();

  projProjTable.createProjTable();                                                    // Create the data list

  projProjTable_ProjTable = projProjTable.parmProjTable().addNew();                   // Add data object instance to data list

  // Initialize the data instance

  projProjTable_ProjTable.parmProjId("P-000003");

  projProjTable_ProjTable.parmName("Test name");

  projProjTable_ProjTable.parmProjGroupId("FixWIP");

  projProjTable_ProjTable.parmType(ProjType::FixedPrice);

  projProjTable_ProjTable.parmProjInvoiceProjId("GTC-19154");

  projProjTable_ProjTable.parmStatus(ProjStatus::InProcess);

  // Create the top level record

  projProjTable_TableDlvAddr = new ProjProjTable_TableDlvAddr();

  // Addind lower level record

  projProjTable_TableDlvAddr.parmAddress("Test Address");

  projProjTable_TableDlvAddr.parmCountryRegionId("PL");

  projProjTable_ProjTable.createTableDlvAddr().add(projProjTable_TableDlvAddr);

  // Create data

  entityKeyList = projTableService.create(projProjTable);

  info("end");

}

Testing service classes and classes for creating records in database

Here first we need to get XML file:

static void  ANG_AIF_TestSerwiceXMLGet(Args _args)

{

  AxdProjTable                                axdProjTable;

  AifEntityKey                                aifEntityKey;

  Map                                         map;

  XMLDocument                                 xmlDocument;

  XML                                         XML;

  AifPropertyBag                              aifPropertyBag;

  FileName                                    fileName;

  fileName    = @"C:\Temp\output.xml";

  map         = new Map(Types::Integer, Types::Container);

  map.insert(fieldNum(ProjTable, ProjId), ['AA-0033']);

  aifEntityKey = new AifEntityKey();

  aifEntityKey.parmTableId(tableNum(ProjTable));

  aifEntityKey.parmKeyDataMap(map);

  try

  {

      axdProjTable    = new AxdProjTable();

      xml             = axdProjTable.read(aifEntityKey, null, new AifEndPointActionPolicyInfo(), new AifConstraintList(), aifPropertyBag);

      new FileIoPermission(fileName, 'rw').assert();

      xmlDocument = XMLDocument::newXml(XML);

      xmlDocument.save(fileName);

      CodeAccessPermission::revertAssert();

  }

  catch

  {

      throw error('Error in document service outbound');

  }

  info("end");

}

After that we should modify that file and run job:

static void ANG_AIF_TestSerwiceXML(Args _args)

{

  XmlDocument                                 xmlDocument;

  AxdProjTable                                axdProjTable;

  FileName                                    fileName;

  //feed the xml that was modified after exporting through exportxml job

  fileName = @"C:\Temp\Test1.xml";

  try

  {

      new FileIoPermission(fileName, 'r').assert();

      xmlDocument     = XmlDocument::newFile(fileName);

      axdProjTable    = new AxdProjTable();

      axdProjTable.create(xmlDocument.xml(), new AifEndPointActionPolicyInfo(), new AifConstraintList());

      CodeAccessPermission::revertAssert();

  }

  catch

  {

      throw error('Error in document service');

  }

  info("end");

}


If you modified xml file correctly then you should have new record in your database.

More articles
Explore our blog

What can we do for you?

We'd love to hear about your project. Our team will get back to you within two working days.

Thank you for inquiry, we’ve passed it to our sales department, our representative will reach you back in his earliest convenience.
Oops! Something went wrong while submitting the form.