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 :
Microsoft Dynamics CRM (Archived)

Restrict or Hide options in option set

(0) ShareShare
ReportReport
Posted on by

Hi, 

In our opportunities form, I'm using 2 option sets to capture the 'Estimated Purchase Time frame'. One for Fiscal year, and one for quarter. Our purchase time frames can span many months and this will let sales managers see a pipeline based on estimated purchase quarter. 

I'm planning for opportunity entries in the future, since removing items from option sets will remove recorded data, I want to hide past fiscal years. Eg. if an opportunity is created in 2018, I want to hide the option 2016 & 2017 from my estimated purchase time frame fiscal year option set. Is this possible?

I checked the business rules, but it only lets you show/hide entire fields, not individual option items.


Is it possible with Javascript?

I would need something to check created on date then hide the options. eg. 

If created on date is greater than Dec. 31 2016, then hide option '2016'

If created on date is greater than Dec. 31 2017, then hide option '2017' etc.


I don't know javascript, where can I find the naming convention for crm fields and entities? 

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    TheMarkChristie Profile Picture
    10,328 Moderator on at

    I would say you would be best to use a business rule

    Make both option sets hidden by default and then setup as so

    5545.Untitled.png

  • Community Member Profile Picture
    on at

    I've tried this business rule, but it hide the entire field. I just want to hide options within a field.

    eg. estimated purchase FY options:

    2016

    2017

    2018

    2019

    when opportunities are created in 2018, I want to hide 2016 & 2017

    if it's too difficult to customize, I'll just leave them there and set the default to the current year, as it's not a huge deal to hide them...maybe if it's 10+ yrs down the line

  • Suggested answer
    TheMarkChristie Profile Picture
    10,328 Moderator on at

    Ahhh ok that makes sense, I would actually then just create a rule and set it automatically for them,

    If created on date >2016 then set value of option set to 2016 - then lock it

  • Suggested answer
    Neil Parkhurst Profile Picture
    10,727 User Group Leader on at

    Try having a look at this ...

    neilparkhurst.com/.../javascript-control-optionset-values

    You can use removeoption in  javascript to hide the options if required.

  • Verified answer
    Jharana Baliyar Singh Profile Picture
    2,667 on at

    Hi cynthia,

    You can remove the option from optionset by using this code :

    Xrm.Page.getControl("optionsetfieldschemaname").removeOption("OptionsetValue")

    By using this it willnot remove from db only it will hide the value.

    Thanks,

  • Suggested answer
    Community Member Profile Picture
    on at

    You can use JS control

  • Community Member Profile Picture
    on at

    Thanks Jharana, this worked.

    Do you know how to add a condition to check the created on date to trigger the function? Will this slow down loading my forms?

    I'm working on contract, so I don't think anyone will be around to manually activate this jscript after I leave. If it will slow down loading, I can just include this in my documentation.

    Thanks

  • Suggested answer
    Neil Parkhurst Profile Picture
    10,727 User Group Leader on at

    The removeOption command only removes the values from the optionset as selectable at runtime. They are still present as possible options in the database. You'd want to create a function that is called from your onload event when the form loads.

    I don't think the performance impact will be significant.

  • Saddamk206 Profile Picture
    777 on at

    Hi,

    Also can try this:-

    for (var i = 0; i < Xrm.Page.getAttribute("FieldName").getOptions().length; i++)
    {

    Xrm.Page.getControl("FieldName").removeOption(Xrm.Page.getAttribute("FieldName").getOptions()[i].value);
    }

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans