Search This Blog

Wednesday, November 30, 2011

how to use Set class in AX

The Set class is used for the storage and retrieval of data from a collection in which the values of the elements contained are unique and serve as the key values according to which the data is automatically ordered.
Scenario:
I have this requirement to track the records that are modified by user and  i  need to take action on mofdied records
Solution with SetsDeclare set in Form\class declaration
Set                         setChangedRecord;
Initialize set on Form\DataSource\init as follows:
setChangedRecord     = new Set(Types::Record);
Store records in set on Write method of the data source as follows
 if (!setChangedRecord.in(purchReqLine))
    {
        setChangedRecord.add(purchReqLine);
    }
Traversing of records in Set:
Following is the way of traversing records from Set
SetEnumerator   setEnumerator    = setChangedRecord.getEnumerator();
 while (setEnumerator.moveNext())
            {
                reqLine = setEnumerator.current();
                if (!reqLine.IsSaved)
                {
                    purchReqLineLocal = PurchReqLine::findRecId(reqLine.RecId,true);
                    purchReqLineLocal.IsSaved = true;
                    purchReqLineLocal.update();
                }

            }

No comments:

Post a Comment

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.