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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to access the Dynamic Control and use OnModified event on DirPartyQuickCreateForm

(1) ShareShare
ReportReport
Posted on by 147
Hi, for my customization, I have added three customized fields to the DirPartyQuickCreateForm form by dragging them into the quickCreateDetails field groups of the CustTable.
 
//
From the figure above, my user requirement is to set if TIN field is filled in, then the Business registration field needs to be changed to a non-mandatory field. If the business registration field is filled in, the TIN field will become non-mandatory.
 
However, I cannot use formControlEventHandler for my fields since they are added as the dynamic control. The system will show me an error message like /Formcontrol DynamicDetail_ads_TIN is not found on the DirPartyQuickCreateForm form./

I write the event handler this way:
[FormControlEventHandler(formControlStr(DirPartyQuickCreateForm, DynamicDetail_ads_TIN), FormControlEventType::Modified)]
    public static void DynamicDetail_ads_TIN_OnModified(FormControl sender, FormControlEventArgs e)
    {
    }

Hence, my question is what should I use to access the dynamic control on DirPartyQuickCreateForm?
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,385 Most Valuable Professional on at
    Your code can't work, because there is no such a control when you compile your code. It's created only later, at runtime, and only then you can subscribe to its events.
     
    You'll need to get a reference of the control (e.g. by iterating controls in DynamicHeader and checking the table/field ID) and then add an event handler at runtime by control.OnModified += eventHandler(...).
  • Yue Zhen Profile Picture
    147 on at
    Hi Sir Martin, can you give me some further explanation on how to get the reference of the control?
  • Layan Jwei Profile Picture
    8,165 Super User 2026 Season 1 on at
    Hi Yue,
     
    You meen you added form controls that are not bound to any datasource? I mean you added the control manually to the form without attaching it to datasource? If this is the case, then I think you should be able to use event handlers, just go to the control and copy event handler, but u can't access the control directly by it's name inside the handler method, you will need sth like this
     
    FormStringControl control = sender.formRun().design().controlName(formControlStr(FormName, YourControl)) as FormStringControl
     
    Or did you add the controls by code?
     
    Also are u getting the error you mentioned without writing anything inside the method?
     
    Thanks,
    Layan Jweihan
  • Yue Zhen Profile Picture
    147 on at
    Hi Layan,
     
    I add the field by dragging the ads_TIN, ads_SSTRegistrationNum, IdentificationNum and the checkbox into a field group of the CustTable, named quickCreateDetails. So the form control is not manually added in the form design. Hence, I cannot use the FormControlEventHandler to add my additional coding logic. Furthermore, I will need to write the FormStringControl as below to access the formControl.

    FormStringControl tin = sender.formRun().design().controlName("DynamicDetail_ads_TIN");
  • André Arnaud de Calavon Profile Picture
    304,551 Super User 2026 Season 1 on at
    Hi Yue,
     
    Are these fields standard or part of a customization? Is the Business registration field mandatory as table property? If the field is not mandatory, you can just add the field and add coding when validating the CustTable record.
  • Martin Dráb Profile Picture
    239,385 Most Valuable Professional on at
    Yen, you didn't explain which part you're struggling with, so I'm assuming it's the first one. Code like this can iterate the controls added at runtime:
    for (int controlNo = 1; controlNo <= DynamicHeader.controlCount(); controlNo++)
    {
        FormControl control = DynamicHeader.controlNum(controlNo);
    }
     
     
     
  • Yue Zhen Profile Picture
    147 on at
    Hi Martin, I think I am struggling with everything haha. I don't understand why do we need to iterate the control in DynamicHeader, because from my current coding, I can get the control by using sender.design().controlName("DyanmicDetail_ads_TIN") like this.
     
    final class DirPartyQuickCreateFrom_Form_Handler
    {
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [FormEventHandler(formStr(DirPartyQuickCreateForm), FormEventType::Initialized)]
        public static void DirPartyQuickCreateForm_OnInitialized(xFormRun sender, FormEventArgs e)
        {
            ads_ConsoEInvoiceParameters consoParameters;
    
            FormCheckBoxControl consoCB = sender.design().controlName("DynamicDetail_ads_ConsolidateEInvCheckbox");
            FormStringControl tin = sender.design().controlName("DynamicDetail_ads_TIN");
            FormStringControl ic = sender.design().controlName("DynamicDetail_IdentificationNumber");
    
            ic.label("Business registration/ identification/ passport number ");
            consoCB.autoDeclaration(true);
            
            select * from consoParameters;
    
            if(consoParameters.ads_ConsolidateEInvCheckbox == 1)
            {
                consoCB.checked(true);
            }
            else
            {
                consoCB.checked(false);
                tin.mandatory(true);
                ic.mandatory(true);
            }
            
            Info(strFmt("%1", consoCB.value()));
        }   
    
    
    }
    I am struggling on how to use an OnModified event handler on my formStringControl for the TIN and IC
  • Martin Dráb Profile Picture
    239,385 Most Valuable Professional on at
    If you're that the name of the control will always be the same, then you can find it by name, but hard-coding the name isn't a good approach. Instead, you something like strFmt('%1_%2', formControlStr(DirPartyQuickCreateForm, DynamicDetail), fieldStr(YourTable, ads_TIN)). This will make sure that the group and the field exist and it'll maintain cross-references.
     
    I already showed you how to a register an event handler method: control.OnModified += eventHandler(...). The parameter of eventHandler() is either an instance method (e.g. this.myMethod or anotherObject.myMethod) or a static method (MyClass::myMethod).
     
    You can see an example in CostStatement form, for instance.
  • Yue Zhen Profile Picture
    147 on at
    Hi Martin, thank you for your prompt explanation. I think I get what you are trying to pass to me now. I will try and update it here later. Thank you for your guidance.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 689

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 606 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 356

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans