How to set a parameter value in CRM 2011?

I have an option installed in CRM 2011. It has four options:

  • Public
  • Private
  • Affiliated undertaking
  • Other

Through the plugin I want to set the value of this option. Can someone provide me with instructions for setting the value of this option?

+5
source share
3 answers

How to set parameter value in plugins

In the plugins you can write yourEntity.yourAttribute = new OptionSetValue(INDEX); INDEX - this is an int that you can find in your parameter editor (the default values ​​are a few digits).

OR

You set the parameter set as yourEntity.Attributes.Add("yourAttribute", new OptionSetValue(INDEX));

+10
source

You can set the parameter value using the following: -

OptionSetValue myOptionSet = new OptionSetValue();
myOptionSet.Value = xxxx  
myEntity.Attributes["optionSetAttributeName"] = myOptionSet;

// xxxx

, myEntity preImage/postImage , , , .

+8

It seemed to me that I would share some code for handling sets of options in CRM here ...

fieldValue = ((OptionSetValue)entity.Attributes[field]).Value.ToString();

//need to get Option Set display label based on its value.  This requires getting attribute metadata
RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest
{
    EntityLogicalName = entity.LogicalName,
    LogicalName = field,
    RetrieveAsIfPublished = true
};

RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)orgContext.Execute(attributeRequest);
EnumAttributeMetadata attributeMetadata = (EnumAttributeMetadata)attributeResponse.AttributeMetadata;

foreach (OptionMetadata om in attributeMetadata.OptionSet.Options)
{
    if (om.Value == ((OptionSetValue)entity.Attributes[field]).Value)
    {
        fieldlabel = om.Label.UserLocalizedLabel.Label;
    }
}

return fieldlabel;
0
source

All Articles