Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Using edit method on f...
Finance forum

Using edit method on form from table extension methods

(0) ShareShare
ReportReport
Posted on by

I created a new extension from table BrazilParameters and created a new method of type edit:

public edit Name profitCenterDimAttributeName (boolean _set, BrazilParameters _brazilParameters, Name _name)
{
    DimensionAttribute dimensionAttribute;

    if (_set)
    {
        dimensionAttribute = DimensionAttribute::findByName(_name);
        this.ProfitCenterDimensionAttribute = dimensionAttribute.RecId;
    }

    return DimensionAttribute::find(this.ProfitCenterDimensionAttribute).Name;
}

Also i have created a form extension to include new fields and my intention is to call the edit method right in the new form field to perform the edit operation:

4885.8284.Capture.PNG

But when i performed the form, the following error showed up:

5873.3808.Capture1.PNG

I can't figure out why this is happened, because the method do exist in the extension. Any guest?

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Using edit method on form from table extension methods

    I just found the mistake in my code. Display and edit method must be STATIC, because under the hood dynamics executes this code from FormUtilClass:

    private static container CallTableDataMethodInExtensionClass(Common _common, str methodName, container inputVariables, boolean newValueIsDefault, str extensionClassName, boolean isStaticMethod)
    {
        container returnContainer;
        anyType returnValue;
        boolean set = false;
        anytype newValue;
        int inputVarsSize = conLen(inputVariables);
    
        DictClass dictClass = new DictClass(className2Id(extensionClassName));
            
        if (dictClass != null)
        {
            DictMethod dictMethod = new DictMethod((isStaticMethod ? UtilElementType::ClassStaticMethod : UtilElementType::ClassInstanceMethod), dictClass.id(), methodName);
                
            if (dictMethod != null)
            {
                // Edit Method
                if (inputVarsSize > 1)
                {
                    set = conpeek(inputVariables, 1);
                    newValue = conpeek(inputVariables, 2);
                    
                    // For instance based edit methods parameter count is 2, as instance extension methods is marked as extension methods to C#, but
                    // static extension methods are not. So for static extension methods, the check for the 3rd optional parameter is needed.
                    int parmOptCheck = isStaticMethod ? 3 : 2;
    
                    // if new value is default and edit method has last argument as optional parameter we want to call method with default argument value.
                    if (newValueIsDefault && dictMethod.parameterOptional(parmOptCheck))
                    {
                        returnValue = dictClass.callStatic(methodName, _common, set);
                    }
                    else
                    {
                        returnValue = dictClass.callStatic(methodName, _common, set, newValue);
                    }
                }
                else // Display method
                {
                    returnValue = dictClass.callStatic(methodName, _common);
                }
            }
        }
    
        returnContainer = conins(returnContainer, 1, returnValue);
        return returnContainer;
    }

    Also the order from my edit method was wrong i fix the code and everything worked as expected.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,302 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,114 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans