Monday, 7 August 2017

Display method in Dynamics 365 for operations

Hi All,
This posts helps you to understand and create a "display"  method for the table extension.
Lets say, the requirement is to add a method in the standard table, it can be achieved either by creating a table extension.
So in this scenario we had a requirement to add a display method in the standard table "CustTrans".
In Dynamics 365 we wont be able to add the new method or modify the existing method to the standard table or to an extension table.
It can be achieved by using the extension class.
Step 1: Create a new class and name it as <Classname>_<Extension>.
<Class-name> - can be any name, but it is preferred to give the table name for which the extension is being created. 
postfix <_Extension> is must.
public static class CustTrans_Extension
{
}
Step 2 : Now add the display methods in the class which is required to be shown.
public static class CustTrans_Extension
{
[SysClientCacheDataMethodAttribute(true)]
public static display AgreementId agreementId(CustTrans _this)
{
LedgerJournalTrans ledgerJournalTrans;
select ledgerJournalTrans
where ledgerJournalTrans.TransactionType == LedgerTransType::Payment &&
LedgerJournalTrans.CustTransId == _this.RecId;

return ledgerJournalTrans.AgreementId;
}
}
Step 3: To use this display method in the form.
Create a string control in the form design and set the following properties
Data source: CustTrans
DataMethod: CustTrans_Extension::agreementId
CacheDataMethod: Yes
Below is the screen shot for reference.
Step 4: Build/Rebuild the project/solution and check the output in the URL.

4 comments:

  1. What if you need to add a display method at the form extension level and set it to a grid fields data method property? (i.e.: myform --> methods --> Display field1)

    I understand how to add display methods to table extensions....but I need to create the display method at the form leave so I have access to form data/datasources in order to query another table and have that be part of my return value.

    I believe I have the methods created correctly....but when referencing that display method on the form objects dataMethod property.....I get this error:

    Path: [AxFormExtension/UnitOfMeasureLookup.Extension/Controls/Copyvsp3k33a1/displayUnitOfMeasureFormulas/DataMethod]:The data method 'UnitOfMeasureLookupForm_Extension::displayTest' was not found on the form 'UnitOfMeasureLookup'

    ReplyDelete
    Replies
    1. Hi Eric,
      Hope this helps.

      https://community.dynamics.com/ax/b/newdynamicsax/archive/2016/10/11/code-behind-extension-forms-how-to-add-state-variable-and-override-methods-without-overlayering

      Delete
  2. If the calss name can be of any name then how does the extension class determines that it belongs to that specific table?

    ReplyDelete
    Replies
    1. Wouldn't that be cause on the form field control Datamethod property you are telling it with class to use? (CustTrans_Extension::agreementId)

      Delete