Search code examples
axaptadynamics-ax-2009x++

How can I control duplicate rows on a temporary table in ax 2009?


I am inserting records to a temp table in a while select query. I need to control that if i added the record before, is it possible?


Solution

  • Use setTmpData method on a second buffer of the same type

    Example:

    SomeTable someTable;
    TmpTable  tmpTable;
    TmpTable  tmpTableCheck;
    
    // Use tmpTable as primary data set, and tmpTableCheck to check for duplicates
    while select someTable
    {
         tmpTable.initFromSomeTable(someTable);
    
         // Check if key is already used.
         tmpTableCheck.setTmpData(tmpTable);
         select firstOnly tmpTableCheck
             where tmpTableCheck.Key == tmpTable.Key;
    
         // Only insert record in tmpTable if the key has not been used before.
         if (! tmpTableCheck)
         {
              tmpTable.insert();
         }
     }