Wednesday, December 3, 2008

Interesting fact about set(Types::Record)


Sets can store data of type record. By definition sets only store unique data, right? So, if you use this construct you should be aware that recId is not taken into account when determining whether a record is already in the set or not. 

Now, in some tables it can be perfectly normal to have records whose only difference is the recId. If you need all instances of these records in your memory storage (set) for further processing, you are better of using a different construct like a recordSortedList, recordInsertList or maybe a map. 

Take inventTrans for example: run the job below on your test system. If you do get a match of set elements and inventTrans records try this: 

Add a sales order line, any item, qty = 2. Go to the inventory transaction, functions/split and make two transactions out of one. Now run the job again. 
The result in my test company: 
214 records in inventTrans 
213 records in record set 

static void SetDuplicates(Args _args) 
    inventTrans inventTrans; 
    set         recordSet = new set(types::Record); 
    int         recordCnt = 0; 
    ; 
    while select inventTrans 
    { 
        recordSet.add(inventTrans); 
        recordCnt++; 
    } 
    print strfmt("%1 records in inventTrans",recordCnt); 
    print strfmt("%1 records in record set ",recordSet.elements()); 
    pause; 

No comments:

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...