Reader small image

You're reading from  Dynamics 365 for Finance and Operations Development Cookbook - Fourth Edition

Product typeBook
Published inAug 2017
Reading LevelIntermediate
PublisherPackt
ISBN-139781786468864
Edition4th Edition
Languages
Right arrow
Authors (2):
Abhimanyu Singh
Abhimanyu Singh
author image
Abhimanyu Singh

Abhimanyu Singh works as a Microsoft Dynamics 365 for Finance and Operations consultant. Since the start of his career in 2012, he has worked in the development and designing of business solutions for customers in supply chain management, banking, and finance domain using Microsoft technologies. He has several certifications, including the Microsoft Certified Dynamics Specialist certification.
Read more about Abhimanyu Singh

Deepak Agarwal
Deepak Agarwal
author image
Deepak Agarwal

Deepak Agarwal is a Microsoft Certified Professional who has more than 6 years of relevant experience. He has worked with different versions of Axapta, such as AX 2009, AX 2012, and Dynamics 365. He has had a wide range of development, consulting, and leading roles, while always maintaining a significant role as a business application developer. Although his strengths are rooted in X++ development, he is a highly regarded developer and expert in the technical aspects of Dynamics AX development and customization. He has also worked on base product development with the Microsoft team. He was awarded the Most Valuable Professional (MVP) award from Microsoft for Dynamics AX four times in a row, and he has held this title since 2013. He shares his experience with Dynamics AX on his blog: Axapta V/s Me Deepak has also worked on the following Packt books: Microsoft Dynamics AX 2012 R3 Reporting Cookbook Dynamics AX 2012 Reporting Cookbook Microsoft Dynamics AX 2012 Programming: Getting Started
Read more about Deepak Agarwal

View More author details
Right arrow

Chapter 2. Working with Forms

In this chapter, we will cover the following recipes:

  • Creating dialogs using the RunBase framework
  • Handling the dialog event
  • Creating dialogs using the SysOperation framework
  • Building a dynamic form
  • Adding a form splitter
  • Creating a modal form
  • Modifying multiple forms dynamically
  • Storing the last form values
  • Using a Tree control
  • Adding the View details link
  • Selecting a Form Pattern
  • Full list of form patterns
  • Creating a new form

Introduction


Forms in Dynamics 365 for Finance and Operations represent the user interface and are mainly used to enter or modify data. They are also used to run reports, execute user commands, validate data, and so on.

Normally, forms are created using the AOT by producing a form object and adding form controls, such as tabs, tab pages, grids, groups, data fields, and images. The form's behavior is controlled by its properties or the code in its member methods. The behavior and layout of form controls are also controlled by their properties and the code in their member methods. Although it is very rare, forms can also be created dynamically from code.

In this chapter, we will cover various aspects of using Dynamics 365 for Finance and Operations forms. We start by building Dynamics 365 for Finance and Operations dialogs, which are actually dynamic forms, and then go on to explain how to handle their events. The chapter will also show you how to build dynamic forms, how to add dynamic controls...

Creating dialogs using the RunBase framework


Dialogs are a way to present users with a simple input form. They are commonly used for small user tasks, such as filling in report values, running batch jobs, and presenting only the most important fields to the user when creating a new record. Dialogs are normally created from X++ code without storing the actual layout in the AOT.

The application class called Dialog is used to build dialogs. Other application classes, such as DialogField, DialogGroup, and DialogTabPage, are used to create dialog controls. The easiest way to create dialogs is to use the RunBase framework. This is because the framework provides a set of predefined methods, which make the creation and handling of the dialog well-structured, as opposed to having all the code in a single place.

In this example, we will demonstrate how to build a dialog from code using the RunBase framework class. The dialog will contain customer table fields shown in different groups and tabs for creating...

Handling the dialog event


Sometimes, in the user interface, it is necessary to change the status of one field depending on the status of another field. For example, if the user marks the Show filter checkbox, then another field, Filter, appears or becomes enabled. In AOT forms, this can be done using the modified() input control event. However, if this feature is required on runtime dialogs, handling events is not that straightforward.

Often, existing dialogs have to be modified in order to support events. The easiest way to do this is, of course, to convert a dialog into an AOT form. However, when the existing dialog is complex enough, a more cost-effective solution would probably be to implement dialog event handling instead of converting into an AOT form. Event handling in dialogs is not flexible, as in the case of AOT forms; but in most cases, it does the job.

In this recipe, we will create a dialog similar to the previous dialog, but instead of entering the customer number, we will be...

Creating dialogs using the SysOperation framework


SysOperation is a framework in Dynamics 365 for Finance and Operations that allows application logic to be written in a way that supports running operations interactively or via the D365 batch server. The SysOperation framework follows the MVC (Model-View-Controller) pattern. As the name implies, the MVC pattern isolates the Model, View, and Controller components, which makes the process loosely coupled built over the SysOperation framework. Depending on parameters, the controller can execute different service operations under four main execution modes. Regardless of which mode a service is running in, the code runs on a server. This makes the minimum number of round trips between server and client.

  • Synchronous: When a service is run in synchronous mode, although it runs on a server, it freezes the Dynamics 365 for Operations browser client. A call is initiated from the client and an object is marshaled to the server to run in CIL. This is...

Building a dynamic form


A standard approach to creating forms in Dynamics 365 for Finance and Operations is to build and store form objects in the AOT. It is possible to achieve a high level of complexity using this approach. However, in a number of cases, it is necessary to have forms created dynamically. In a standard Dynamics 365 for Finance and Operations application, we can see that application objects, such as the Table browser form, various lookups, or dialogs, are built dynamically. Even in Dynamics 365 for Finance and Operations, where we have a browser-based interface, every form or dialog opens in a browser only.

In this recipe, we will create a dynamic form. In order to show how flexible the form can be, we will replicate the layout of the existing Customer groups form located in the Accounts receivable module. The Customers form can be opened by navigating to Accounts receivable | Setup | Customers.

How to do it...

Carry out the following steps in order to complete this recipe...

Adding a form splitter


In Dynamics 365 for Finance and Operations, complex forms consist of one or more sections. Each section may contain grids, groups, or any other element. In order to maintain section sizes while resizing the form, the sections are normally separated by so-called splitters. Splitters are not special Dynamics 365 for Finance and Operations controls; they are Group controls with their properties modified so that they look like splitters. Most of the multisection forms in Dynamics 365 for Finance and Operations already contain splitters.

In this recipe, in order to demonstrate the usage of splitters, we will modify one of the existing forms that does not have a splitter. We will modify the Account reconciliation form in the Cash and bank management module. You can open this module by navigating to Cash and bank management | Setup | Bank group. From the following screenshot, you can see that it is not possible to control the size of each grid individually and that they are...

Creating a modal form


Often, people who are not familiar with computers and software tend to get lost among open application windows. The same can be applied to Dynamics 365 for Finance and Operations. Frequently, a user opens a form, clicks a button to open another one, and then goes back to the first one without closing the second form. Sometimes this happens intentionally, sometimes not, but the result is that the second form gets hidden behind the first one and the user starts wondering why it is not possible to close or edit the first form.

Although it is not best practice, sometimes such issues can be easily solved by making the child form a modal window. In other words, the second form always stays on top of the first one until it is closed. In this recipe, we will make a modal window from the Create sales order form.

How to do it...

Carry out the following steps in order to complete this recipe:

  1. Add the SalesCreateOrder form in the project and set its Design property:

Modifying multiple forms dynamically


In the standard Dynamics 365 for Finance and Operations, there is a class called SysSetupFormRun. The class is called during the run of every form in Dynamics 365 for Operations; therefore, it can be used to override one of the common behaviors for all Dynamics 365 for Finance and Operations forms. For example, different form background colors can be set for different company accounts, some controls can be hidden or added depending on specific circumstances, and so on.

In this recipe, we will modify the SysSetupFormRun class to automatically add the About Dynamics 365 for Operations button to every form in Dynamics 365 for Finance and Operations.

How to do it...

Carry out the following steps in order to complete this recipe:

  1. Add a new project, name it MultipleForm, and change the model to Application Platform, as shown in the following screenshot:
  2. Add the FormRun class and create a new method with the following code snippet:
private void addAboutButton() ...

Storing the last form values


Dynamics 365 for Finance and Operations has a very useful feature that allows you to save the latest user choices per user per form, report, or any other object. This feature is implemented across a number of standard forms, reports, periodic jobs, and other objects which require user input. When developing a new functionality for Dynamics 365 for Finance and Operations, it is recommended that you keep it that way.

In this recipe, we will demonstrate how to save the latest user selections. In order to make it as simple as possible, we will use the existing filters on the Bank statement form, which can be opened by navigating to Cash and bank management | Common | Bank accounts, selecting any bank account, and then clicking on the Account reconciliation button in the Action pane. This form contains one filter control called View, which allows you to display bank statements based on their status. The default view of this form is Unreconciled. We will see how to...

Using a tree control


Frequent users will notice that some of the Dynamics 365 for Finance and Operations forms use tree controls instead of the commonly used grids. In some cases, this is extremely useful, especially when there are parent-child relationships among records. It is a much clearer way to show the whole hierarchy, as compared to a flat list. For example, product categories are organized as a hierarchy and give a much better overview when displayed in a tree layout.

This recipe will discuss the principles of how to build tree-based forms. As an example, we will use the Budget model form, which can be found by navigating to Budgeting | Setup | BasicBudgeting | Budget models. This form contains a list of budget models and their submodels and, although the data is organized using a parent-child structure, it is still displayed as a grid. In this recipe, in order to demonstrate the usage of the Tree control, we will replace the grid with a new Tree control.

How to do it...

Carry out...

Selecting a form pattern


In the latest version of Dynamics 365 for Finance and Operations, form patterns are now an integrated part of the form development experience. These patterns provide form structure based on a particular style (including required and optional controls), and also provide many default control properties. In addition to top-level form patterns, Dynamics 365 for Operations has also introduced subpatterns which can be applied to container controls, and that provide guidance and consistency for subcontent on a form, such as, on a Fast Tab.

Form patterns have made form development easier in Dynamics 365 for Finance and Operations by providing a guided experience for applying patterns to forms to guarantee that they are correct and consistent. Patterns help validate form and control structures, and also the use of controls in some places. Patterns also help guarantee that each new form that a user encounters is immediately recognizable in appearance and function. Form patterns...

Full list of form patterns


In the current version of Dynamics 365 for Finance and Operations, there are a total of five form patterns that we use the most:

  • Details Master
  • Form Part - Fact Boxes
  • Simple List
  • Table of Contents
  • Operational workspaces

For a full list of the forms that are currently using a particular form pattern, generate the Form Patterns report from within Microsoft Visual Studio. On the Dynamics 365 menu, expand the Add-ins option, and click Run form patterns report. A background process generates the report. After several seconds, a message box appears in Visual Studio to indicate that the report has been generated and inform you about the location of the Form Patterns report file. You can filter this file by pattern to find forms that use a particular pattern.

How to do it...

We're going to look at how to run the form patterns report. This report is generated through Visual Studio and gives us information about all of the forms in the system with the corresponding form patterns...

Creating a new form


In Dynamics 365 for Finance and Operations, form creations are slightly easier than in AX2012 and earlier versions. Here, we have more tools to create any specific form using design templates. Every form plays an important role where we need to interact with the user to view, insert, update, or delete any record(s).

In this recipe, we will create a simple form using a template and add this form to one of the menus so that users can access it from the front end.

Getting ready

Let's think about a scenario where the admin needs to check all existing users in the system. Although we have one standard form for this, we cannot give access to everyone because this form also has many other options to perform on this form, while our requirement is to just see read only data. We will use this form in further recipes to justify the name of this form. Here, it will show all enabled and disabled users.

How to do it...

  1. Add a new form in your project name it PktDisabledUsers.
  2. Expand the Data...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Dynamics 365 for Finance and Operations Development Cookbook - Fourth Edition
Published in: Aug 2017Publisher: PacktISBN-13: 9781786468864
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Abhimanyu Singh

Abhimanyu Singh works as a Microsoft Dynamics 365 for Finance and Operations consultant. Since the start of his career in 2012, he has worked in the development and designing of business solutions for customers in supply chain management, banking, and finance domain using Microsoft technologies. He has several certifications, including the Microsoft Certified Dynamics Specialist certification.
Read more about Abhimanyu Singh

author image
Deepak Agarwal

Deepak Agarwal is a Microsoft Certified Professional who has more than 6 years of relevant experience. He has worked with different versions of Axapta, such as AX 2009, AX 2012, and Dynamics 365. He has had a wide range of development, consulting, and leading roles, while always maintaining a significant role as a business application developer. Although his strengths are rooted in X++ development, he is a highly regarded developer and expert in the technical aspects of Dynamics AX development and customization. He has also worked on base product development with the Microsoft team. He was awarded the Most Valuable Professional (MVP) award from Microsoft for Dynamics AX four times in a row, and he has held this title since 2013. He shares his experience with Dynamics AX on his blog: Axapta V/s Me Deepak has also worked on the following Packt books: Microsoft Dynamics AX 2012 R3 Reporting Cookbook Dynamics AX 2012 Reporting Cookbook Microsoft Dynamics AX 2012 Programming: Getting Started
Read more about Deepak Agarwal

Property

Value

WindowType...