Skip to main content

Notifications

Announcements

No record found.

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

How to access a method in a form using extensions

(0) ShareShare
ReportReport
Posted on by 1,433

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,433 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,156 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,673 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.

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... 291,904 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,605 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans