How to cache records on run-time in AX?

The simple answer is RecordViewCache class. This class is used to implement set-based caching in your code at run-time.

1.    First declare the variables.

CustTrans                    custTrans;
RecordViewCache      recordViewCache;

2 .  Call a nofetch query to create a record buffer. It will define the set of records that you want to cache.

//Define records to cache
select nofetch custTrans
where custTrans.AccountNum == ‘4000’;

3.   Pass the record buffer to instantiate RecordViewCache Object. It will also cache the records that are returned in the buffer.

recordViewCache  =  new RecordViewCache(custTrans);

4.   The records in the following query will be returned from the cache.

select firstOnly custTrans  where custTrans.AcccountNum == ‘4000’ &&
custTrans.CurrencyCode == ‘USD’;

One thought on “How to cache records on run-time in AX?

Leave a Reply

Your email address will not be published. Required fields are marked *