D365 Finance and supply chain ( F&O) : Adding custom fields on create product form via extension framework Approach

If you have added new fields in products table via extension, then their are high chances that you will also be asked to add them on the standard create product dialog.

Initially it may look like a simple task to add 2 fields on a form but when you will start developing and will have a look inside the form design you will notice that there is no data source on this form design and hence you cannot just add the fields by drag and drop feature.

No Datasource in the form design

Upon technical analysis , you will find that there is a method named createData2Controls() which basically populates a container with details of which controls on the form are mapped to which fields of the tables and then under the method writeMoreFields(), the container is read and the fields are assigned value based on the mappings present in the container.

Below is how we can use extension framework approach to add new fields to the form and add the mapping in the container.

  • Add new fields to Invent table. In my case I added 2 new fields.
  • Create extension of the EcoresProductCreate form and add unbounded controls on the form design. Set Auto declaration as True.
  • Create a new extension class and decorate it with attribute [ExtensionOf(formStr(EcoResProductCreate))].
  • In the new class , extend the method createdata2Controls() to add the mapping of your new fields on the table extension with the form unbounded controls . Below is the sample
[ExtensionOf(formStr(EcoResProductCreate))]
final class XYZ_EcoResProductCreate_Extension
{
    protected void createData2Controls()
    {
        next createData2Controls();

        data2Controls = conIns(data2Controls,
                                conLen(data2Controls) + 1,
                                [tableStr(InventTable), [[fieldNum(InventTable, YourFieldName1), formControlStr(EcoResProductCreate, YourControlName1)]]]);

        data2Controls = conIns(data2Controls,
                                conLen(data2Controls) + 1,
                                [tableStr(InventTable), [[fieldNum(InventTable, YourFieldName2), formControlStr(EcoResProductCreate, YourControlName2)]]]);

    }

}

After this build the project area and run the product create process and the values will flow to the inventTable.

Hope this helps if you are trying to figure out how to use extension framework to feed the value of new controls to the table.

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 )

Google photo

You are commenting using your Google 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

A WordPress.com Website.
%d bloggers like this: