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 :
Supply chain | Supply Chain Management, Commerce
Answered

Loop through all form controls X++ generically

(0) ShareShare
ReportReport
Posted on by 5

We're trying to fulfil a requirement to be able to assign different properties to a certain form controls under different companies, and is trying to achieve it using some generic code rather than doing it on a per-form basis.

We've tried the following code to loop all controls within a form, however is unsuccessful, the code only returned button controls within the top action pane.

Any idea how to revise it to make it work, for example, to be able to return all individual field controls under a grid, in the SalesTable form?

[ExtensionOf(classStr(FormRun))]
final class XXX_FormRun_Extension
{
public void run()
{
next run();

for (int i = 1; i <= this.form().design().controlCount(); i++)
{
this.XXX_iterateControls(this.form().design().controlNum(i));
}
}

protected void XXX_iterateControls(FormBuildControl formBuildControl)
{
info(strFmt("%1 %2", formBuildControl.isContainer(), formBuildControl.controlCount()));

if (formBuildControl.isContainer())
{
for (int j = 1; j < formBuildControl.controlCount(); j++)
{
//Process container, if you need to
this.XXX_iterateControls(formBuildControl.controlNum(j));
}
}
else
{
//Control is not a container, process it here.
info(strFmt("%1 %2", classId2Name(formBuildControl.handle()), formBuildControl.name()));

switch (formBuildControl.handle())
{
case classNum(FormBuildRealControl):
info("Found");
break;
}
}
}

}

I have the same question (0)
  • Verified answer
    Blue Wang Profile Picture
    on at

    HI JohnnyKu ,

    Have you tried to use New Metadata API?

    https://community.dynamics.com/365/financeandoperations/b/goshoom/posts/new-metadata-api

    About properties , I think you should read this: community.dynamics.com/.../loop-on-all-controls-in-a-form

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    Could you share any additional details about your requirement? What kind of functional changes are you trying to achieve?

  • Suggested answer
    JohnnyKu Profile Picture
    5 on at

    Thanks Blue, I'm able to resolve my issue using the Metadata API.

  • JohnnyKu Profile Picture
    5 on at

    Hi Nikolaos, basically our requirement is that there could be different properties required per company (e.g., number of decimals displayed for a particular field), and we do not want to modify it on a per-form basis. That's why we were exploring a generic way of doing it.

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    Sounds cool, hopefully it works out! I guess you can't change it on infologs or reports but just having it changed on all form fields would be definetely useful in some scenarios.

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 > Supply chain | Supply Chain Management, Commerce

#1
Laurens vd Tang Profile Picture

Laurens vd Tang 298 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 179 Super User 2025 Season 2

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans