web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
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,461

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.

I have the same question (0)
  • Verified answer
    Sukrut Parab Profile Picture
    71,741 Moderator on at

    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.

  • Verified answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    Cast the sender variable to a variable of type FormRun:

    FormRun callerForm = sender as FormRun;

    callerForm.myMethod();

  • Retha Profile Picture
    1,461 on at

    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.

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 > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans