Skip to main content

Add table to a default description in D365 FO

 

Purpose:

The purpose of this post is to demonstrate how can we extend default descriptions by adding a new table to the default description definition.

Application:

Dynamics 365 Finance and Operations

Prerequisites:

  • Understanding of how default descriptions work

Business requirement:

Use customer free text invoice line description field in the definition of Customer – tax invoice, customer default description.

Out of the box only two tables are available to select, CustInvoiceTable and CustInvoiceJour. The requirement is to add CustInvoiceLine.

Solution:

It can be achieved by developing an extension class of TransactionTextContextCust class.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
[ExtensionOf(classStr(TransactionTextContextCust))]
final class TransactionTextContextCustMAK_Extension
{
    private CustInvoiceLine custInvoiceLine;
 
    /// <summary>
    /// Provides a list of tables that are supported for use with a specified transaction type.
    /// </summary>
    /// <returns>
    /// A container that contains a collection of <c>TableId</c> values of tables that are supported by a
    /// specified transaction type.
    /// </returns>
    public container getSupportedTables()
    {
        container tableList;
 
        tableList = next getSupportedTables();
 
        tableList += tableNum(CustInvoiceLine);
 
        return tableList;
    }
 
    /// <summary>
    /// Sets the parameter variable of an object to contain the records that are used with a specified
    /// transaction type.
    /// </summary>
    /// <remarks>
    /// This method must be called before the table fields and values are mapped for the transaction text
    /// setup parameters.
    /// </remarks>
    public void setParameters()
    {
        next setParameters();
 
        parameters = [custInvoiceJour, custInvoiceTable, custInvoiceLine];
    }
 
    /// <summary>
    /// Set a particular table buffer for a specified transaction type.
    /// </summary>
    /// <param name="_common">
    /// The <c>Common</c> record that is set based on the <c>TableId</c> value of the buffer.
    /// </param>
    /// <returns>
    /// true if the table is supported and the buffer is saved; otherwise, false.
    /// </returns>
    /// <remarks>
    /// The <c>Common</c> record is cast to the appropriate table through switch logic.
    /// This method can be called repeatedly to assign multiple buffers.
    /// </remarks>
    /// <exception cref="M:Exception::Error">
    /// The table is not supported by this transaction type.
    /// </exception>
    public boolean setTableBuffer(Common _common)
    {
        boolean tableBufferSet;
 
        tableBufferSet = next setTableBuffer(_common);
 
        switch (_common.TableId)
        {
            case tableNum(CustInvoiceTable):
                custInvoiceLine = CustInvoiceLine::findByParentRecId(custInvoiceTable.RecId);
                tableBufferSet = true;
                break;
        }
 
        return tableBufferSet;
    }
 
}

Comments