Sunday, April 7, 2013

How To: Clear or Delete data from an AX container

Using the conDel Function [AX 2012], a user can delete certain elements from a container. When these elements are removed, the numbering in the container will adjust accordingly so that the numbers will always be sequential

There are three parameters container conDel(container container, int start, int number):
  1. container container
    1. the container that the user wishes to have the data deleted from
  2. int start
    1. the spot in the container to start deleting values
      1. If this number is 0, it will not delete anything
      2. The number given will actually be deleted (e.g. 2 will actually include element 2 in the deletion)
  3. int number
    1. the number of elements to delete in the container
      1. If this number is larger than the container, it will delete everything from the start value on
static void daxTestDelContainer(Args _args)
{
    container   test = ['a','b','c','d','e','f','g','h','i']; 
    container   testManip = test;
    int         i; 

       
    info ("BEGIN TEST - the container data in full");
    // Cycle (iterate) through the container
    for (i=1; i <= conlen(testManip); i++)
    {       
       info(strFmt("%1 - %2", i, conpeek(testManip, i)));
    }        

      
    info ("TEST conDel(testManip, 0, 3) - Remove 3 at spot 0");
    testManip = conDel(testManip, 0, 3);
    // Cycle (iterate) through the container
    for (i=1; i <= conlen(testManip); i++)
    {       
       info(strFmt("%1 - %2", i, conpeek(testManip, i)));
    }    

    
    info ("TEST conDel(testManip, 1, 3) - Remove 3 at spot 1");    
    testManip = conDel(testManip, 1, 3);
    // Cycle (iterate) through the container
    for (i=1; i <= conlen(testManip); i++)
    {       
       info(strFmt("%1 - %2", i, conpeek(testManip, i)));
    }

    
    // Reset the container
    testManip = test;    

    
    info ("TEST conDel(testManip, 2, 3) - Remove 3 at spot 2");
    testManip = conDel(testManip, 2, 3);          
    // Cycle (iterate) through the container
    for (i=1; i <= conlen(testManip); i++)
    {       
       info(strFmt("%1 - %2", i, conpeek(testManip, i)));
    }

    
    // Reset the container
    testManip = test;

    
    info ("TEST conDel(testManip, 3, 5) - Remove 5 at spot 3");
    testManip = conDel(testManip, 3, 5);          
    // Cycle (iterate) through the container
    for (i=1; i <= conlen(testManip); i++)
    {       
       info(strFmt("%1 - %2", i, conpeek(testManip, i)));
    }

    
    // Reset the container
    testManip = test;

    
    info ("TEST conDel(testManip, 3, 50) - Remove 50 (more than container has) at spot 2");
    testManip = conDel(testManip, 3, 50);          
    // Cycle (iterate) through the container
    for (i=1; i <= conlen(testManip); i++)
    {       
       info(strFmt("%1 - %2", i, conpeek(testManip, i)));
    }
}
 
Figure 1 - Infolog from the above code
 
 

No comments:

Post a Comment