Store the parameter selection on a form by using the SysLastValue framework

When we have a dialog form open in order to run some operation in Dynamics 365 for Finance and Operations, there are often some parameters to enter. Usually such forms are not bound to any data source so a user have to manually enter parameters on the form. It might be annoying if each time when the dialog prompts, a user needs to enter the same parameters all over again, before running the corresponding operation. That’s why many such built-in dialogs use the SysLastValue framework that enables storing the last parameter selection on a dialog for a user, so the next time the user open that dialog its fields get populated with the user’s last parameter choice. For example, one such dialog which we all know is the Print destination settings form invoked from a report dialog form.

Let’s suppose that we have a dialog created which needs to collect some parameters for monthly invoice emailing. These parameters are marked on the form you can see on the picture below: Emailing invoices ID, Email ID, Purpose and Send to.

Take a look on how the SysLastValue framework is used on this form to achieve storing the parameter selection for a user.

We introduced the form fields (emailingInvoicesIdVar, emailIdVar, sendToVar, purposeVar) for the parameters whose values we are going to store with the SysLastValue framework, and pack and unpack them in the corresponding methods. When the form is closed, the xSysLastValue::saveLast(this) method is called, which invokes the pack() form method and the resulting container is saved with the SysLastValue framework. And vice versa – when the form is open, the xSysLastValue::getLast(this) method is called, which invokes the unpack() form method to set the form fields (emailingInvoicesIdVar, emailIdVar, sendToVar, purposeVar). After this method, the form controls get initialized from these form fields in the setControlValuesFromSysLastValues() method.

Download the working example >>

Leave a Reply

Your email address will not be published.


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

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