D365FO SysLastValue Framework Simplified

D365FO SysLastValue Framework Simplified

SysLastValue is a handy framework in Dynamics 365 for Finance and Operations (D365FO). It saves the values you enter in forms for the current user within the current company so that the next time you open the form, your previous entries are already there. Originally introduced in AX 2012, this framework has been improved in D365FO with two new methods: getValue() and putValue(), making it easier to use.

SysLastValue: Old vs. New (simplified) framework

Before, using SysLastValue meant writing a bunch of different methods. The methods are hard to find in the documentation and are loosely coupled (e.g., no interface is implemented in standard D365FO), which means if you do not implement them, you will get an error in the runtime. Now, with the new methods putValue() and getValue(), you can save and retrieve values with just a single line of code.

Just as a reminder, previously we had to implement the following methods in our class:

  • lastValueUserId()
  • lastValueType()
  • lastValueElementName()
  • lastValueDesignName()
  • lastValueDataAreaId()
  • initParmDefault()
  • pack()
  • unpack()
  • xSysLastValue::getLast(Object _caller)
  • xSysLastValue::saveLast(Object _caller)
You can check our article Store the parameter selection on a form by using the SysLastValue framework to see how the old way was used.

These values are accessible from Settings > User options > Usage data > All usage data and are stored in the SysLastValue table which is located in the AOT browser under the System Documentation > Tables node.

  

You can view the data in the table using SysTableBrowser or, even better, with the improved Docentric Table Browser, which is available in the Docentric Free Edition.

Now let's see how we can use the new way to store and retrieve values from the SysLastValue framework.

Storing values

To store values, use the putValue() static method from the xSysLastValue class.

Here’s how the method looks:

Here's what each parameter means:

  • _value: A container of values to store.
  • _company: The company ID.
  • _userId: The user ID.
  • _type: The type of element (like Form, Class, Report, etc.). You can list all element types by opening the UtilElementType base enum under System Documentation > Base Enums in AOT browser.
  • elementName: The name of the element.
  • designName: An optional name for additional text if you need it (usually used to store the design name of the property/object to which the data belongs).

Retrieving values

To get your stored values back, use the getValue() static method from the xSysLastValue class. This method returns a container with the values you saved using the putValue() method.

Here's how the method looks:

The parameters are the same as the ones you used with putValue().

How these methods work in practice

Now that we understand how the methods work, let’s look at an example of how they are used in practice.

These methods are used in the Docentric Print Management Utilities to check customer and vendor email addresses. For example, you can easily find customers without email addresses, ensuring your email print jobs run smoothly.

The Print Management Utilities feature and many more can be found in the Docentric Free Edition. To see which ones are available, please check out our feature list.

We used the new SysLastValue framework to filter out print management setting overrides by only selected customers. Here’s how you do it:

  • Open the Print Management Utilities (go to Docentric AX workspace > Print management tab page > Utilities).
  • Click on the Customer without email menu item, which opens a dialog.
  • Use the Records to include filter to specify customers.
  • Click the Show button.

At this point, the SysLastValue framework ensures that the filter remains the same the next time you open the dialog.

Below is the code showing how the query is stored in SysLastValue (see the selected line below):

And here is how the query is retrieved from SysLastValue (see the selected line below):

Conclusion

In this article, we have explained and demonstrated how to use the SysLastValue framework with just a single line of code. While the old way required implementing several additional methods, this new approach undoubtedly saves you time and is much more straightforward.
 

2 thoughts on “D365FO SysLastValue Framework Simplified

    1. Thank you very much sir! 😀
      Always when we learn something new while developing our product, we want to share it with the community – because we truly believe that growing and sharing knowledge empowers us all in our community to do better what we do and what we are very passionate about!

Leave a Reply

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

*

Docentric respects your privacy. Learn how your comment data is processed >>

Docentric respects your privacy. Learn how your comment data is processed >>