Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

How to Get Control Name on the Form for JavaScript to Use in formContext.getControl(arg) Client API

Posted on by 3,405

The new modern form editor is not giving the control names the same as the schema name of the field when you place the fields on the form using the new modern WYSIWYG form editor.
It generates the control names such as "Single-line_text_1" which does not make sense for the developers to reference with the actual field.

That makes it harder for us to find the control name and use in formContext.getControl("new_fieldname") for Control Client APIs suchs as (setVisible, setLabel, etc.)

How do you normally get the control name if repeated controls are presented on the form with _2, _3 or controls placed with modern form editor such as "Single-line_text_1"?
Browser DevTools (F12) or any other tool?

What is the best approach to get Control Control Client APIs for the fields placed on the form using modern form editor?

This is the best way I can think of but is there any better way?

formContext.getAttribute("new_fieldname").controls.forEach(function (control, index) { control.setVisible(false); });

Or we should not use the modern form editor to place the fields at all until the issue is resolved?

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: How to Get Control Name on the Form for JavaScript to Use in formContext.getControl(arg) Client API

    Hi Linn,

    Sorry for misunderstanding,

    I thought that your code that getting all controls by field's attribute/schema name would be the best method at present.

    Regards,

    Clofly

  • Linn Zaw Win Profile Picture
    Linn Zaw Win 3,405 on at
    RE: How to Get Control Name on the Form for JavaScript to Use in formContext.getControl(arg) Client API

    Hi @cloflyMao

    Thanks for your response.

    What I am actually looking for is a way to get the attribute Control name (not attribute schema name) which can be different

    - if you add multiple controls of the same field to the form (which is postfix with _2, _3, etc. when you add from the classic form editor)

    - if you add the field onto the form using the modern form editor which generates the control names such as "Single-line_text_1"

    I did't see any option to show "Control names" in the "Level up for Dynamics CRM/365" extension.

    Maybe I will try to submit a pull request when I have some spare time.

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How to Get Control Name on the Form for JavaScript to Use in formContext.getControl(arg) Client API

    Hi,

    I guess the best way i what you have mentioned. As MS can change the name style in future, this is the safest way.

    formContext.getAttribute("new_fieldname").controls.forEach(function (control, index) { control.setVisible(false); });

    Hope this helps.

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: How to Get Control Name on the Form for JavaScript to Use in formContext.getControl(arg) Client API

    Hi Linn Zaw Win,

    You could install a extension called "Level up for Dynamics CRM/365" if your browser is Chrome,

    https://chrome.google.com/webstore/detail/level-up-for-dynamics-crm/bjnkkhimoaclnddigpphpgkfgeggokam?hl=en

    https://github.com/rajyraman/Levelup-for-Dynamics-CRM

    it'll show all tabs, sections and fields shcema name by clicking a button, which could help you locate these elements quickly.

    pastedimage1572837569455v2.png

    Regards,

    Clofly

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans