Platform API: Improvements to the PK.Find Method

In MYOB Acumatica 2024.1, a new optional parameter, options, has been introduced in the PK.Find method. By using this parameter, developers can specify whether the Dirty cache can be used, as well as whether the global cache should be used..

Note: The introduction of this new parameter has caused multiple changes in the PK.Find methods of the application code, which are listed in the Removed Methods section of the Reference List of Changes chapter of Release Notes for Developers. If a developer has used any of the modified PK.Find methods, they need to recompile the extension library of their customization project without any changes.

Use of the Dirty Cache

In previous versions of MYOB Acumatica, a developer could not put the record returned by the PK.Find method in the cache including the Current property of the cache; the developer also could not change the returned record. Now a developer can specify whether the Dirty cache should be used, which gives the developer the ability to utilize the record returned by the PK.Find method in any place, including the cache.

To specify that the records marked as Dirty in the cache (that is, updated, inserted, or deleted in the cache) should be included in the query result, the developer should specify the PKFindOptions.IncludeDirty flag when calling the Find method. An example is shown in the following code.

shipmentEntry.Document.Current = SOShipment.PK.Find(shipmentEntry, 
                                                    doc.ShipmentNbr, 
                                                    PKFindOptions.IncludeDirty);

Ignoring of the Global Cache

If a developer wants to retrieve a record from the cache and exclude the result from the global cache, they can provide the PKFindOptions.SkipGlobalCache value for the options parameter. Ignoring the global cache may be needed, for example, when a record has been modified by multiple graphs at a time, and the developer needs to retrieve a record that has been modified by one of them. Because the global cache is updated only once during a round trip to the server, the modified value of the record is not stored in the global cache.
Note: The use of the IncludeDirty option also ignores the global cache.