Monday, June 1, 2015

Set Option Set by Text or Value Using Java Script

Suppose the following scenario, you have an option set  on a Dynamics CRM 2011 form and you want
to change the selected item or it have no selected item currently and you would like to set it.
You have to 2 ways to do it.
  • By Value
    Xrm.Page.getAttribute(“optionsetAttribute”).setValue(value);
  • By Text
    Actually you can’t set the selected item by text by you can search all options untill you find the on whose text (label) is the same as one the one you have then get its value
    setOptionSetByOptionText = function(optionsetAttribute, optionText)
    {
    var options = Xrm.Page.getAttribute(optionsetAttribute).getOptions();for(i = 0; i < options.length; i++)
    {if (options[i].text == optionText)Xrm.Page.getAttribute(optionsetAttribute).setValue(options[i].value);
    }
    }
    Example : setOptionSetByOptionText (“new_nationality”,”American”);

No comments:

Post a Comment

How to Deploy your API as a web app or API app

  Before you can call your custom API from a logic app workflow, deploy your API as a web app or API app to Azure App Service. To make your ...