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?

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: