2014-01-21 68 views
0

我想從我的CRMOnline獲取OptionSet鍵=>值。我有權訪問SOAP端點並能夠執行所有CRUD操作。如何從選項集SalesStageCode中獲取信息,以便我可以在外部帳戶創建表單中的下拉列表中顯示該信息。獲取CRM OptionSet數據

回答

1

我相信你應該使用RetrieveAttribute消息。重新檢查this article

0

A C#從CRM 2011 Programatically Finding the Values of Picklists, Optionsets, Statecode, Statuscode and Boolean (Two Options).版本

static Dictionary<String, int> GetNumericValues(IOrganizationService service, String entity, String attribute) 
{ 
    RetrieveAttributeRequest request = new RetrieveAttributeRequest 
    { 
     EntityLogicalName = entity, 
     LogicalName = attribute, 
     RetrieveAsIfPublished = true 
    }; 

    RetrieveAttributeResponse response = (RetrieveAttributeResponse)service.Execute(request); 

    switch (response.AttributeMetadata.AttributeType) 
    { 
     case AttributeTypeCode.Picklist: 
     case AttributeTypeCode.State: 
     case AttributeTypeCode.Status: 
      return ((EnumAttributeMetadata)response.AttributeMetadata).OptionSet.Options 
       .ToDictionary(key => key.Label.UserLocalizedLabel.Label, option => option.Value.Value); 

     case AttributeTypeCode.Boolean: 
      Dictionary<String, int> values = new Dictionary<String, int>(); 

      BooleanOptionSetMetadata metaData = ((BooleanAttributeMetadata)response.AttributeMetadata).OptionSet; 

      values[metaData.TrueOption.Label.UserLocalizedLabel.Label] = metaData.TrueOption.Value.Value; 
      values[metaData.FalseOption.Label.UserLocalizedLabel.Label] = metaData.FalseOption.Value.Value; 

      return values; 

     default: 
      throw new ArgumentOutOfRangeException(); 
    } 
} 

OptionSetValue optionSetValue = new OptionSetValue(GetNumericValues(proxy, "new_test", "new_local")["One"]);