Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Remove Option set value dynamically.

(0) ShareShare
ReportReport
Posted on by 2

When I was trying to remove the "status code"  value using java script. It is showing the following error.

"Object doesn't support property or method 'removeOption'" . Add/Remove option for the status code option set is not working. Please let me know if there is any other way to remove the values..?

This issue is only with CRM 2015 online Update 1. 

Can any one help me please..?

*This post is locked for comments

  • RE: Remove Option set value dynamically.

    Status Reason Transitions existed prior to 2015 update 1.  I'm having the exact same issue after upgrading our CRM 2015 to CRM 2016 (on premise) on the Account entity.

  • Suggested answer
    James Reinhardt Profile Picture
    James Reinhardt 222 on at
    RE: Remove Option set value dynamically.

    I'm having the same issue and can replicate exactly what you are seeing. I think that 2015 (or 2015.1) changed the way that status reasons are handled and added in the "Status Reason Transitions" for this. The status reason field looks like an optionset, but it will not allow Optionset Control Methods.


    Status reason transitions are really pretty cool, I'd suggest using them anyway.

  • Hamzeh Zawahreh Profile Picture
    Hamzeh Zawahreh 3,674 on at
    RE: Remove Option set value dynamically.

    check this post

    community.dynamics.com/.../161007

  • Abhiram Thulasi Profile Picture
    Abhiram Thulasi 2 on at
    RE: Remove Option set value dynamically.

    hello,

    I have gone through this, but I didn't  get a solution.

    I just want to remove one of the option set value of an option set called "Status Reason" it s back end name is "statuscode".

  • Hamzeh Zawahreh Profile Picture
    Hamzeh Zawahreh 3,674 on at
    RE: Remove Option set value dynamically.

    hello,

    read this it will help you:

    crmbusiness.wordpress.com/.../crm-2013-understanding-status-and-status-reason-and-be-careful-deleting-them

  • Abhiram Thulasi Profile Picture
    Abhiram Thulasi 2 on at
    RE: Remove Option set value dynamically.

    Hi Hamzeh,

    I tried with this function which is not working in CRM 2015 Update1. By using this code we can remove the normal option set value, but not able to add or remove "Status Reason" values.

  • Suggested answer
    Hamzeh Zawahreh Profile Picture
    Hamzeh Zawahreh 3,674 on at
    RE: Remove Option set value dynamically.

    dear Abhiram Thulasi

     

    try this code below:


    Remove Optionset Value at Runtime – MS CRM 2011

    Create Js webresource with below code:


    function removeOptionSetValue(attributeName, value, index) {
    var attrName = attributeName;
    if (index != undefined && index != null) {
    attrName = attrName + index;
    index += 1;
    }
    else {
    index = 1;
    }
    var attrControl = Xrm.Page.getControl(attrName);
    if (attrControl != null) {
    try {
    attrControl.removeOption(value);
    removeOptionSetValue(attributeName, value, index);
    } catch (e) {

    }
    }
    }

     

    function RemoveOptions()

    {

    removeOptionSetValue(“optionsetname”,value, null);

    }

    so it will remove the value from optionset.

     

     

  • Abhiram Thulasi Profile Picture
    Abhiram Thulasi 2 on at
    RE: Remove Option set value dynamically.

    Hi Guido Preite,

    Thanks for you replay.

    Please find the following code.

    function hideConfirmedStatus() {

       var picklistType = "statuscode";

       var picklistTypeName = Xrm.Page.getControl(picklistType);

       var picklistTypeAttribute = picklistTypeName.getAttribute();

       var picklistTypeSelectedOption = picklistTypeAttribute.getSelectedOption();

       var statusCode = Xrm.Page.getControl("statuscode").getAttribute().getSelectedOption();

       var picklistMode = "md_mode";

       var picklistModeName = Xrm.Page.getControl(picklistMode);

       var picklistModeAttribute = picklistModeName.getAttribute();

       var picklistModeSelectedOption = picklistModeAttribute.getSelectedOption();

       var picklistModeSelectedText = "";

       if (picklistModeSelectedOption != null) {

           picklistModeSelectedText = picklistModeSelectedOption.text;

       }

       var Amount = Xrm.Page.getAttribute("md_amount").getValue();

       if (statusCode != null) {

           statusCodeText = statusCode.text;

       }

       if (statusCodeText != 'Confirmed') {

           picklistTypeName.removeOption(899230002);

       }

       var opt2 = new Option();

       opt2.text = "Confirmed";

       opt2.value = 899230002;

       //alert(Xrm.Page.data.entity.attributes.get("md_unitsaleid").getValue());

       if (picklistModeSelectedText != "") {

           if ((picklistModeSelectedText != "Payable Adjustment") && (picklistModeSelectedText != "Fund Transfer")) {

               if ((Amount == 0) || (Amount == null)) {

               }

               else if (statusCodeText != "Confirmed") {

                   if ((Xrm.Page.data.entity.attributes.get("md_fromunitsaleid").getValue() != null) || (Xrm.Page.data.entity.attributes.get("md_unitsaleid").getValue() != null) || (Xrm.Page.data.entity.attributes.get("md_unitleasingid").getValue() != null) || (Xrm.Page.data.entity.attributes.get("md_contact").getValue() != null) || (Xrm.Page.data.entity.attributes.get("md_corporatecustomerid").getValue() != null)) {

                       picklistTypeName.addOption(opt2);

                   }

               }

           }

           else {

               if ((Xrm.Page.data.entity.attributes.get("md_fromunitsaleid").getValue() != null) || (Xrm.Page.data.entity.attributes.get("md_unitsaleid").getValue() != null)) {

                   if (statusCodeText != "Confirmed") {

                       picklistTypeName.addOption(opt2);

                   }

               }

           }

       }

       if (picklistModeSelectedText == "Payable Adjustment") {

           var lookupObject = Xrm.Page.getAttribute("md_payableid");

           if (lookupObject != null) {

               var lookUpObjectValue = lookupObject.getValue();

               if ((lookUpObjectValue == null)) {

                   picklistTypeName.removeOption(899230002);

               }

           }

       }

       if (picklistModeSelectedText == "Fund Transfer") {

           var formType = Xrm.Page.ui.getFormType();

           var serverUrl = Xrm.Page.context.getClientUrl();

           //var customServerURL = document.location.protocol + "//" + document.location.host + "/" + Xrm.Page.context.getOrgUniqueName();

           //if(serverUrl != customServerURL)

           //{

           //serverUrl = customServerURL ;

           //}

           var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";

           if (formType != 1) {

               var receiptid = Xrm.Page.data.entity.getId();

               var retrieveReq = new XMLHttpRequest();

               var filter = "/md_fundacquisitionSet?" +

                            "$select=md_fundacquisitionId" + "&$filter=md_Receipt/Id eq guid'" + receiptid + "'";

               retrieveReq.open("GET", ODataPath + filter, false);

               retrieveReq.setRequestHeader("Accept", "application/json");

               retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8");

               retrieveReq.send(null);

               var retrievedRecords = JSON.parse(retrieveReq.responseText).d;

               if (retrievedRecords.results.length > 0) {

               }

               else {

                   picklistTypeName.removeOption(899230002);

               }

           }

           else {

               if ((Xrm.Page.data.entity.attributes.get("md_fromunitsaleid").getValue() == null) || (Xrm.Page.data.entity.attributes.get("md_unitsaleid").getValue() == null)) {

                   picklistTypeName.removeOption(899230002);

               }

           }

       }

    }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,817 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans