Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / how to call method o...
Finance forum

how to call method on Standard Form OR form - DS methods

(0) ShareShare
ReportReport
Posted on by 18

Dear all,

Can you please let me know how  to call  method on Standard Form OR form - DS methods in standard form?

Please give me more she'd on this

Thanks!

  • Verified answer
    Sukrut Parab Profile Picture
    71,682 Moderator on at
    RE: how to call method on Standard Form OR form - DS methods

    Yes new methods  you have to add in extension . In above case you are able to achieve your requirement using event handler , which can be implemented by creating simple class.

  • @rp@n Profile Picture
    18 on at
    RE: how to call method on Standard Form OR form - DS methods

    Thanks bro,

    That means when i wants to add new method in Standard form then it should be always done by "ExtensionOf " only.

    The above code which i did i think "ExtensionOf " is NOT required for this because i am going to visible False of control only not going to add any new method.

    is't correct?

  • Verified answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: how to call method on Standard Form OR form - DS methods

    You can use ExtensionOf with Chain of Command to wrap the init method of the form and achieve the same result as you did with your event handler.

    Event handlers existed in D365FO (and AX) already before Chain of Command was introduced. And still there are scenarios where event handlers are the only solution. But there is a big overlap in what you can achieve with event handlers and CoC. The benefit of CoC is that you can access protected variables, enhance protected methods and include your code in the same transaction scope as the standard code. There's also better compile time check for your code, and it's easier to read and write.

    In addition to CoC, class augmentation (ExtensionOf) can also be used to add completely new methods to standard objects.

  • Verified answer
    Sukrut Parab Profile Picture
    71,682 Moderator on at
    RE: how to call method on Standard Form OR form - DS methods

    Extension of is used when you want to create extension  of object. You did right thing by not mixing event handler implementation in extension class.  When you want to add suppose any method on the form then you are going to create extension class for that form and add method in that, same thing applies to tables classes etc.

  • @rp@n Profile Picture
    18 on at
    RE: how to call method on Standard Form OR form - DS methods

    Hi All,

    I am creating a New class like "CustTableEventHandler".

    Then i will go CustTable form > Events >OnInitialized > CopyEventHandlerMethod

    A1.jpg

    Class CustTableEventHHandler

    {

        [FormEventHandler(formStr(CustTable),FormEventType::Initialized)]
        public static void CustTable_OnInitialized(xFormRun sender,FormEventArgs e)
        {
            //Then i will set field to visible false
            sender.design().controlName(formControlStr(CustTable, MCRMerged)).visible(false);
        }
    }
    Then i build the project it's working fine.

    I follow the below link

    https://blogs.msdn.microsoft.com/mfp/2018/12/05/chain-of-command-on-forms/

    When i will use "ExtensionOf..." ?

    Please give me more shed on this.

    Thanks!

  • Piyush Adhikari Profile Picture
    2,544 on at
    RE: how to call method on Standard Form OR form - DS methods

    Good explanation

    docs.microsoft.com/.../method-wrapping-coc

  • Verified answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: how to call method on Standard Form OR form - DS methods

    If you have the FormRun in a variable, you can call your methods on the form.

    1. Add this method in your form (using "ExtensionOf" augmentation, if it's a standard form):

    public FormDataSource getMyDataSource()
    {
        return MyTable_ds();
    }


    2. Call the methods of formRun:

    myFormRun.myMethod(); // This calls method "myMethod" in your form
    
    FormDataSource myDataSource = myFormRun.getMyDataSource();
    myDataSource.refresh(); // This calls method refresh of your form data source


  • Piyush Adhikari Profile Picture
    2,544 on at
    RE: how to call method on Standard Form OR form - DS methods

    allaboutmsdynamics.wordpress.com/.../d365-ax7call-any-method-of-caller-form-in-a-class-or-any-other-form-or-extension-etc

    Call any method of caller form into a class or any other form

    Requirement

    Here is very impressive piece of code for calling any method of custom or base form in a class or any form.

    In standard form “PurchCreateFromSalesOrder” there is a base method specifyVendAccount which i need to call on extension class of form “PurchCreateFromSalesOrder” on the modification of a new custom control i have created separately on the same form “PurchCreateFromSalesOrder“.

    Sample Code With Explanation

    I created one class and a new event method.

    [FormControlEventHandler(formControlStr(PurchCreateFromSalesOrder, FormStringControl1), FormControlEventType::Modified)]

    public static void FormStringControl1_OnModified(FormControl sender, FormControlEventArgs e)

    {

    FormRun formRun =sender.formRun();

    SalesLine salesLine;

    FormDataSource formDataSource;

    Object formRunObject;

    ;

    salesLine = SalesLine::findRecId(68719716393);

    formRunObject = formRun.dataSource(1);

    formRunObject.specifyVendAccount(true, SalesLine, ‘INMF-000001’); //here i am calling the method of  form datasource

    formRun.dataSource(1).write();

    formRun.dataSource(1).research(true);

    formRun.dataSource(1).refresh();

    }

  • Verified answer
    Sukrut Parab Profile Picture
    71,682 Moderator on at
    RE: how to call method on Standard Form OR form - DS methods

    you csn use COC for forms and it's  datasource.

    blogs.msdn.microsoft.com/.../chain-of-command-on-forms

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... 294,095 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans