Tuesday, September 25, 2012

Simple AX container example

Below is a simple example of creating and inserting values into a container, determining the size of the container, and looping over that container to retrieve the values from it.

Since this is a job and I wanted to test out embedding methods into the job, I included that little complexity in here. All that it does is either fill the container with data or leave it empty based on the 'dataInCont' value which stands for data in container. Note that this variable is a global so when declared in that location and using embedded functions/methods, this location acts as the class declaration.

This is AX development 101 stuff but I was using it in a training sample so I decided I might as well slap the code on my blog as well as the resulting information log.

Enjoy!


static void daxTestJob(Args _args)
{
    container cont;
    int i;
    boolean dataInCont = true; // Do we want to run this job with container data? Note this is a global
   
    // This method will either return an empty container or one with data
    container test()
    {
        container contTest;
       
        if (dataInCont)
        {
            contTest += 5;
            contTest += 6;
            contTest += -52;
            contTest += 'DAXDUDE';           
        }
       
        return contTest;
    }
    ;
          
    cont = test();
   
    info (strFmt("Length of the container: %1", conLen(cont)));
   
    for (i=1; i <= conLen(cont); i++)
    {
        info (strFmt("container value %1 is %2", i, conPeek(cont, i)));  
    } 
}

Resulting infolog from code above:

No comments:

Post a Comment