CRM 2011 Javascript – working with Option sets

If we want to write the value of an option set in a text field.

 
function onyearchange() {
    var myOptionSet = Xrm.Page.data.entity.attributes.get("lema_year");
    var optionSetText = myOptionSet.getText();
    Xrm.Page.getAttribute("lema_name").setValue(optionSetText);
}

If we need to set the value of an option set based on a text

 

function SetOptionSetValueByText(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);  
  }  
 }  



SetOptionSetValueByText("lema_year","2014");

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s