Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

How to access a variable inside a form in event handlers?

(0) ShareShare
ReportReport
Posted on by 1,550

Hi,

I want to be able to get CaseDetailForm inside the event handler But I'm getting formRun doesn't contain this field

[Form]
public class CaseDetailCreate extends FormRun
{
    CaseDetailForm caseDetailForm;
}

    [FormControlEventHandler(formControlStr(CaseDetailCreate, OK), FormControlEventType::Clicked)]
    public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)
    {
            FormRun formRun = sender.formRun();
            CaseDetailForm c = formRun.CaseDetailForm;
    }

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: How to access a variable inside a form in event handlers?

    Hi,

    As Martin mentioned you can go for extension.

    But to solve this issue you can create one parm method and return "caseDetailsForm" buffer.

    You can later call that method using form Run.

    [Extensionof(formStr(FormName))]
    final class className
    {
        public CaseDetailsForm getCaseDetail()
        {
            return caseDetailForm;
        }
    }

     [FormControlEventHandler(formControlStr(CaseDetailCreate, OK), FormControlEventType::Clicked)]
        public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)
        {
                FormRun formRun = sender.formRun();
                CaseDetailForm c = formRun.getCaseDetail();
        }

    Thanks,

    Girish S.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,848 Most Valuable Professional on at
    RE: How to access a variable inside a form in event handlers?

    You made thing more complicated than necessary by using an event handler instead of an extension. If you, for example, extend close() method of the form, you can refer to the variable simply by its name.

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to access a variable inside a form in event handlers?

    Hi check this article

    https://wp.me/p76m04-fx

    Is CaseDetailForm a form control?

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