Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / How to access a method...
Finance forum
Answered

How to access a method in a form using extensions

Posted on by 1,427

I have an extension class on form ReqTransPo.

I need to on initialized reference the method InventDimSetupObject().

[FormEventHandler(formStr(ReqTransPo), FormEventType::Initialized)]

public void ReqTransPo_OnInitialized(xFormRun sender, FormEventArgs e)

{

 showStorageDimensionColumns = NoYes::Yes;

InventDimParm InventDimParmLocal = sender.inventDimSetupObject().inventDimSetupObject.parmDimParmVisibleGrid();

InventDimParmLocal.InventLocationIdFlag = true;

InventDimParmLocal.InventSiteIdFlag = true;

}

However I get the error: Class 'xFormRun' does not contain a definition for method 'inventDimSetupObject'.

This method is under the form methods and it is not defined as private or protected, which in both cases won't allow me to access it in an extension.

So how do I get ahold of it? I need to load the form with the inventory dimension InventLocationId and InvetnSiteId visible in the grid by default. The user doesn't want to every time they go into this form to have to click on view > Display > Dimensions and select warehouse and site.

Any suggestions are much appreciated.

  • Retha Profile Picture
    Retha 1,427 on at
    RE: How to access a method in a form using extensions

    Thank you Sukrut and Nikolaos

    I tried your suggestions before and it didn't work.

    However when  I tried it again I noticed I had a typo:

    inventDimSetupObject().inventDimSetupObject.parmDimParmVisibleGrid();

    should have been: inventDimSetupObject().parmDimParmVisibleGrid();

    I also had to move it to the OnPostRun event because the class in InvntDimSetupObject() was still empty OnInitialized .

    [FormEventHandler(formStr(ReqTransPo), FormEventType::PostRun)]

       public  void ReqTransPo_OnPostRun(xFormRun sender, FormEventArgs e)

       {

           FormRun callerForm = sender as FormRun;

           InventDimParm InventDimParmLocal = callerForm.inventDimSetupObject().parmDimParmVisibleGrid();

           InventDimParmLocal.InventLocationIdFlag = true;

           InventDimParmLocal.InventSiteIdFlag = true;

           InventDimParmLocal.WMSLocationIdFlag = false;

           InventDimParmLocal.LicensePlateFlag = false;

       }

    Thanks for your help.

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to access a method in a form using extensions

    Cast the sender variable to a variable of type FormRun:

    FormRun callerForm = sender as FormRun;

    callerForm.myMethod();

  • Verified answer
    Sukrut Parab Profile Picture
    Sukrut Parab 71,645 Moderator on at
    RE: How to access a method in a form using extensions

    Did you try this

    FormRun form = sender.formRun();

    DirPartyLookupEntitiesFilter dirPartyLookupEntitiesFilter = form.getDirPartyLookupEntitiesFilter();

    You can find plenty of examples in Application explorer . This example is from class DirPartyLookupFormEventHandler which is handler class for DirPartyLookup form.

Helpful resources

Quick Links

Dynamics 365 Community Update

Welcome to the inaugural Community Platform Update. As part of our commitment to…

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Community Spotlight of the Month

Kudos to Mohana Yadav!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,142 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,979 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans