Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

How to access form control from a RunBaseBatch class ?

(0) ShareShare
ReportReport
Posted on by 592

Hi guys,

I have a RunBaseBatch class which mainly will be running on batch. But this class will also available on a form for manual run.

As far as I know, to "identify" whether this class is called by a form or not, I need to have this statement : 

 if (callerForm.name() == formstr(MyForm))
 {
                   .....
 }

Question is how to reach the form control as well ? because after this class is ran completely (when it is called from the FORM), I will need to direct the TabPage of MyForm. So in that form I have two TabPage : Detail and Overview Grid, just like SalesTable form when we open first time will be the grid list and we can click SalesId then it will switch to Detail TabPage. So I want to direct the form to always viewing the TabPage that contain/display the GridList right after my RunBaseBatch completed.

Thanks

  • Voltes Profile Picture
    Voltes 592 on at
    RE: How to access form control from a RunBaseBatch class ?

    It works.

    This is what I needed. Thanks so much, Mohit.

  • Verified answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to access form control from a RunBaseBatch class ?

    Args is not required here.

    Please try below code in the Clicked method

    FormRunViewOptionHelper viewOptionHelper = element.viewOptionHelper();
    viewOptionHelper.setViewOption(FormViewOption::Grid);

  • Voltes Profile Picture
    Voltes 592 on at
    RE: How to access form control from a RunBaseBatch class ?

    Hi Mohit,

    Yes, that is what I'm trying to say, since it is a custom form. 

    Anyway actually I also tried the element like this : 

    pastedimage1684386000030v1.png

    But it doesn't switch to Grid.

    Anything wrong with the statement ?

    Thanks,

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to access form control from a RunBaseBatch class ?

    For Custom form, Extensions (Event Handler or CoC) is not required. You can override Clicked method of button and add your code in the form itself.

    To access FormRun in clicked method use keyword 'element'.

  • Voltes Profile Picture
    Voltes 592 on at
    RE: How to access form control from a RunBaseBatch class ?

    Hi Mohit,

    Works for event handler, but since this is a custom form anyway, may I know if we don't want to use Event Handler class ? I mean I tried to make less new classes. So I think from the clicked button is more like for my approach. But I'm still don't know how to set the ViewOption from the FormRun of myform.

    Thanks,

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to access form control from a RunBaseBatch class ?

    You check this thread

    community.dynamics.com/.../919018

    But I think easy solution for you will be creating Event Handler for Clicked method and changing the view as specified in the article.

    https://dynamicsaxknowledge.wordpress.com/2021/04/17/set-form-view-option-dynamically/

    Let us know which one you tried and worked.

  • Voltes Profile Picture
    Voltes 592 on at
    RE: How to access form control from a RunBaseBatch class ?

    Hi Mohit,

    That actually good idea. It is called from MenuItem button. I guess I'm overthinking of this.

    However may I know how to direct it from the click button then ?

    Thanks,

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to access form control from a RunBaseBatch class ?

    Hi, You must be calling this RunBaseBatch class either via MenuItem or calling menu item on click of a button. Instead of accessing form control in class, how about writing your code in Clicked method of that button.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans