No items found.

AIF testing in AX 2012

  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.

See more

AGA pomaga – poznaj inteligentnego asystenta do przetwarzania zapytań ofertowych: ANEGIS Generative Assistant

Read article
Text Link

Jak z pomocą narzędzi Power Platform, Microsoft Fabric i AI zrealizować plan na cyfrową transformację? ANEGIS Power Center

Read article
Text Link

Obowiązkowy KSeF startuje za 4 miesiące! Umów się na bezpłatne konsultacje i przygotuj swój system na zmiany

Read article
Text Link
Back to all

Let's talk about your project

Let us know what you need: implementation, migration, system development, or a question you’re looking to have answered. We’ll get back to you with a concrete proposal for the next step - not a sales pitch.

Thank you for your message!
Oops! Something went wrong while submitting the form.
Microsoft AI Builder
Microsoft Copilot Studio
No items found.
No items found.
No items found.