Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

hide multiple fields in CRM using wildcard for fieldnames

Posted on by 1,575

Hello,

I want to hide several fields via an onchange event for a yes/no field on a CRM form.

The field names all have the same prefix so is there any way I can use a wildcard to set the visibility of all the fields based on their fieldname.

So instead of individually:

Xrm.Page.ui.controls.get("new_sg2_text1").setVisible(true);
Xrm.Page.ui.controls.get("new_sg2_text2").setVisible(true);
Xrm.Page.ui.controls.get("new_sg2_text3").setVisible(true);

I would like something like

Xrm.Page.ui.controls.get("new_sg2_%").setVisible(true);

Many thanks for any suggestions.

- Seamus

*This post is locked for comments

  • Verified answer
    naresh babu Profile Picture
    naresh babu 425 on at
    RE: hide multiple fields in CRM using wildcard for fieldnames

    You can use Business rules.

  • Seamus Profile Picture
    Seamus 1,575 on at
    RE: hide multiple fields in CRM using wildcard for fieldnames

    Thanks Ambar!

  • Verified answer
    RE: hide multiple fields in CRM using wildcard for fieldnames

    its different

    in place of setdisable write setvisible ,as below

    entityObject.attributes.forEach(function (control, index) {

    if (attributeEnableList.indexOf(control.getName()) == -1 && !control.getName().toString().includes(".")) {

    entityObject.attributes.getByName(control.getName()).controls.getByName(control.getName()).setVisible(false);

    }

    });

    if its helped then please mark as resolved to help it other

  • Seamus Profile Picture
    Seamus 1,575 on at
    RE: hide multiple fields in CRM using wildcard for fieldnames

    Thanks Ambar, - sorry for being slow to grasp this but (a) how I would I amend your code to use the wildcard "new_sg2_" and (b) is setDisabled the same as setVisible? Many thanks again.

  • Suggested answer
    RE: hide multiple fields in CRM using wildcard for fieldnames

    Hello ,

    Use below .

    entityObject.attributes.forEach(function (control, index) {
    if (attributeEnableList.indexOf(control.getName()) == -1 && !control.getName().toString().includes(".")) {
    entityObject.attributes.getByName(control.getName()).controls.getByName(control.getName()).setDisabled(true);
    }
    });

    you could change the check condition as per your need .

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans