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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

is this the formContext version of foreach?

(0) ShareShare
ReportReport
Posted on by

Is the upgrade from Xrm.Page version I found elsewhere?

                    formContext.ui.controls.forEach(function (control, i) {
                        if (control && control.getDisabled && !control.getDisabled()) {
                            control.setDisabled(true);
                        }
                    });

And if I wanted to limit this to just the attribute controls, how do I use this feature I found in the documentation:

formContext.data.entity Attribute.controls

Tia

I have the same question (0)
  • LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    About the difference between "formContext.ui.controls" and "formcontext.data.entity.Attribute.controls", you could refer to the following picture.

    pastedimage1583981593676v1.png

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/clientapi-form-context

    Actually, they have the same function. ui.controls could get all the controls on the current page and entity.attribute.controls could get the controls on the current entity form.

    If you only want to get the attribute controls in entity form, you could use formContext.getControl() to do actions on controls.

    Best Regards,

    Leo

  • Community Member Profile Picture
    on at

    Good reference!  Bad news is that I'm not someone who understands the statement "non-entity bound attributes."  Good news is that I think what I'm after is the other thing.

    So what I understand you are saying is that to avoid everything but on-form attribute controls the syntax is like:

    formContext.data.entity.attributes.forEach(attr, i)

    ...attr.controls.forEach(ctrl, j)...

    where most of the second forEach will handle only one control.

    NOTE: I tried doing the setDisabled on the attributes and nothing happened, probably because attributes are not controls.

    thanks again

  • Suggested answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    Actually your understanding is correct.

    In "forEach" cycle, you could handle only one control. And the reason why "setDisabled" is useless is that you should get the control to set disabled not attributes.

    As we can see in the doc, we should use formcontext.getControl().setDisabled();

    pastedimage1584323912585v1.png

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/setdisabled

    Hope it helps.

    Best Regards,

    Leo

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 74 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans