Creating a module in Microsoft Dynamics 365: Create the Parameters Table [Part 3]

This post is part of a series on creating a module within a Microsoft Dynamics 365 for Finance and Operations application. Links to the other parts are available in the first post: Creating a Module in Microsoft Dynamics 365: Laying the Foundation.

A module in Microsoft Dynamics 365 for Finance and Operations is a grouping of similar business processes and functions that allow users to conduct business. Examples include General Ledger, Accounts Receivable, Accounts Payable, and many others. Developers create new modules to group new functionality in an equivalent manner or to produce third-party solutions.

In this series, I am creating a fictitious module called Generic Application Solution (GAS). The assumption will be that the reader has an intermediate knowledge of development in Dynamics 365 as well as best practices. This post will build upon the foundation laid in the first two posts by creating the parameters table.

Parameter tables are special because they only have one record for each legal entity and their purpose is to store parameters used within a module. There are many examples of parameter tables: CustParameters, VendParameters, InventParameters, and others.

Small modules may not need a parameters table but most of the time they will need number sequences and future versions of the module might need parameters. The recommendation is to include a parameters table in a new module.

Create the Table

Creating a parameters table is identical to creating a regular table with some differences. It is best practice to name a parameter table with the name of mode followed by “Parameters” (for example, GASParameters).

Table properties of a parameter table

The following are the key properties. Developers may need to set them after later steps of creating the module.

  • Label: Assign the name of the table.
  • Cache Lookup: Set to Found.
  • Table Group: Set to Parameter.
  • Configuration Key: Assign the name of the module’s configuration key.
  • CreateRecordIdIndex: Set to No.
  • FormRef: Assign the name of the parameter form’s menu item (which should be the same as the name of the form).
  • PrimaryIndex: Set to KeyIdx (see below).
  • ClusterIndex: Set to KeyIdx (see below).

Create Field and Index

Screen shot of a parameter table in D365FO showing the Key field and KeyIdx index

At the minimum, a parameters table needs one field named Key. This field is an integer and has both the Visible and Mandatory properties set to No. Developers add additional fields to hold parameters needed by the module.

Parameter tables have a single unique index named KeyIdx. This index has a single field: Key. The PrimaryIndex and ClusterIndex properties on the table get the name of this index.

Add Required Methods

The parameters table should have a static find method and override the delete and update methods.

    public static GASParameters find(boolean _forupdate = false)
    {
        GASParameters parameter;
        
        if (_forupdate)
        {
            parameter.selectForUpdate(_forupdate);
        }

        select firstOnly parameter
            index KeyIdx
            where parameter.Key == 0;
 
        if (!parameter)
        {
            Company::createParameter(parameter);
        }

        return parameter;
    }

 

    public void delete()
    {
        throw error("@SYS23721");
    }

 

    public void update()
    {
        super();
        flush GASParameters;
    }

In prior versions, developers added a call to the static find method on the parameters table in the selectParametersPost method of the Company class. In Dynamics 365, this method is no longer available. Instead, developers need to subscribe to the onSelectParameters delegate of the Company class. The call to the static find method goes into the handler.

    [SubscribesTo(classStr(Company), delegateStr(Company, onSelectParameters))]
    public static void Company_onSelectParameters()
    {
        GASParameters::find();
    }

That concludes the creation of the parameters table. Next, I will discuss the creation of the parameters form.

References

Advertisement

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 )

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