Search code examples
containersaxaptadynamics-ax-2012x++

How to write in container field table from code?


I have a simple question, I have in my Table a Field. This field is type container .

How I can write in this field.

I used this code, but don't work:

MyTable myTable;
str value = "value" ;
ttsBegin;
select forupdate myTable;
conIns( myTable.FieldContainet, 1 , value );
myTable.insert();
ttsCommit ;

Solution

  • Containers are immutable, you therefore have to assign the result of conIns to your container field:

    myTable.FieldContainet = conIns(myTable.FieldContainet, 1, value);
    

    Try to use myTable.FieldContainet += value; instead, it is easier to read and performs better.

    Second method, if exist container initialized value:

    container con;
    con = ["valueI" , "valueII" , "valueIII"];
    //other code
    myTable.FieldContainet = con;
    

    Copy all the values contained in container.