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)

Hide/Disable a selectable value in an Option List

(0) ShareShare
ReportReport
Posted on by 100

I have an Option List that is populated with Years.  As a year expires, I'd like to remove it from being selected from the Option List.  I'd like this value to continue to display on historical records, but I seem to be having great difficulty in making this happen.

  • Removing it the actual Option set seems to remove the reference to the "2014" label, so historical records show up as blank.  This is not acceptable.'
  • Utilizing the Javascript solution of Xrm.Page.getControl('field name').removeOption(value); also seems to come with the drawback that when viewing this a historical via the Form...it also blanks out the field making look like it was never set.  Not really acceptable.
  • I've tried to utilize unsupported javascript to select the particular Options that I want to remove and remove them.  I've gotten it to work for IE10, but cannot seem to get it to correctly run in IE9.  It doesn't seem to understand which frame to look in.
    • function FilterFiscalYear(){ $("select[attrName='sgs_fiscalyear'] option[title='2014']").each( function() { $(this).remove(); });}

I'm entirely baffled as to why it's so difficult to remove an option from an Option set, but leave the historical data displaying that value that's no longer selectable.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Deepesh161 Profile Picture
    6,317 on at

    Make a html webresource which internally fetches option set , sets it but only show the ones you want in your select control.

  • Kelly Grant Profile Picture
    100 on at

    Thanks for your quick reply.  Can you provide any examples of how to do this?  I'm not quite following what you've recommended.

    Are you recommending that I use Jscript to clear the Option Set.  Query the Options I want.  And then use  Xrm.Page.getControl('field name').addOption(value,index) to populate the Option Set with my desired list?

  • Verified answer
    Deepesh161 Profile Picture
    6,317 on at

    No, I am suggesting to fetch option set values in html webresourcr(keep it hidden on form).

    You will also know current year in script.

    Build a dynamic select control in html (show all years except current one)

    Reference to form a dynamic select control: http://stackoverflow.com/questions/7340644/dynamically-add-input-type-select-with-options-in-javascript

    When somebody changes selection in your resource on the background set your option set.

    Hope it is more clear now.

  • 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);
    }

  • Community Member Profile Picture
    on at

    I ended up making a custom entity and then replaced the Picklist with a Lookup to the custom entity.  This would let me disable records so they were no longer selectable, but retained their value for historical reporting.

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