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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Filter Optionset

(0) ShareShare
ReportReport
Posted on by 222

Hi All,

I have an optionset field in two different tabs. I need to filter the options in optionset according to a value in another field.

I am using the javascript on the change of value for that field. I am able to filter the options as well.

But the problem is, the options are getting filtered only for the optionset present in the Summary tab and not in the other tab though the schema name of the field is same.

The code i have used is:

var optionsetControl = Xrm.Page.ui.controls.get("fieldschemaName");
var options = optionsetControl.getAttribute().getOptions();

optionsetControl.clearOptions();

Is it possible to get the control of attribute using label of field instead of schema name

Please suggest any help.

Thanks

*This post is locked for comments

I have the same question (0)
  • Aparna1 Profile Picture
    222 on at
    RE: Filter Optionset

    Thanks Ridhima. I already tried it but unfortunately it was getting filtered only for one tab.

    Thanks

  • Aparna1 Profile Picture
    222 on at
    RE: Filter Optionset

    Temmy, Thanks a lot it is working very nicely.

    Previously I used Xrm.Page.getControl("new_problemtype1") so it was not working. But when I used Xrm.Page.getControl("new_problemtype2"), it got resolved.

    Thanks

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Filter Optionset

    Hi Aparna,

    You can use the values of the optionset and use its length. Check conditions based on tabs.

    Please check below code hope it helps

    var tab = Xrm.Page.ui.tabs.getAll();
    if(tab=="tabname")
    {
    var optionsetControl = Xrm.Page.ui.controls.get("fieldschemaName");
    var options = optionsetControl.getAttribute().getOptions();

    optionsetControl.clearOptions();


    for (var i = 0; i < options.length; i++) {
    if (i < 5) {
    optionsetControl.addOption(options [i])
    }
    }

    }

    else if(if tab=="othertabname")
    {

    var optionsetControl = Xrm.Page.ui.controls.get("fieldschemaName");
    var options = optionsetControl.getAttribute().getOptions();

    optionsetControl.clearOptions();

    for (var i = 0; i < options.length; i++) {
    if (i < 6) {
    optionsetControl.addOption(options [i])
    }
    }

    }


    }

    Thanks

    Ridhima

  • Aparna1 Profile Picture
    222 on at
    RE: Filter Optionset

    Hi Temmy,

    Thanks for the solution but still it is not working.

  • Verified answer
    Temmy Wahyu Raharjo Profile Picture
    2,914 on at
    RE: Filter Optionset

    Usually if you add same attribute twice in form. Crm automatically will add "name"+n. So let say when you access problem type is using Xrm.Page.getControl('new_problemtype"). So if you want to access another control you need to use Xrm.Page.getControl("new_problemtype1"). So in short u need to applied those function in 2 different controls.

  • Aparna1 Profile Picture
    222 on at
    RE: Filter Optionset

    I have the same optionset in two different tabs.

    Example: "Problem Type" optionset present in Tab 1 and also in Tab2.

    When I apply the method to filter options, I am able to see only filtered options for "Problem Type" in Tab1 but I can see all the options under "Problem type" in Tab2 which means it is not getting filtered for Tab2. The field is same which is present in the two tabs.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Filter Optionset

    Hi Aparna ,

    I am sorry , I could not understand questions .

    What is your requirement? can you please give some more details .

    You can refer below thread , might be useful for you.

    community.dynamics.com/.../289497

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans