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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
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

I have the same question (0)
  • Abhiram Thulasi Profile Picture
    2 on at

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

               }

           }

       }

    }

  • Suggested answer
    Hamzeh Zawahreh Profile Picture
    3,674 on at

    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
    2 on at

    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.

  • Hamzeh Zawahreh Profile Picture
    3,674 on at
  • Abhiram Thulasi Profile Picture
    2 on at

    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
    3,674 on at

    check this post

    community.dynamics.com/.../161007

  • Suggested answer
    James Reinhardt Profile Picture
    222 on at

    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.

  • Lucas Blackburn Profile Picture
    on at

    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.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans