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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to access form control from a RunBaseBatch class ?

(0) ShareShare
ReportReport
Posted on by 596

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

I have the same question (0)
  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    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.

  • Voltes Profile Picture
    596 on at

    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,

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    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
    596 on at

    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
    12,565 Moderator on at

    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
    596 on at

    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,

  • Verified answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    Args is not required here.

    Please try below code in the Clicked method

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

  • Voltes Profile Picture
    596 on at

    It works.

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans