locked
Request list of type incident RRS feed

  • Question

  • Hello,

    How to request the list of incident type"casetypecode" with C# code?

    incident.casetypecode = new PickList();

    thanks
    Jean Akiyo
    Wednesday, March 11, 2009 6:57 PM

Answers

  •  

    Hi Jean

    You can get the options from a picklist attribut from the MS CRM Meta Database.  The method below returns a picklists options as a DataTable. The method takes two string values. First is the entity name that the picklist is on. Second is the attributname of the picklist.


    Hope this helps you.

    /c

    www.dollerupit.dk


     
    public static DataTable GetPicklistValue(string entity, string picklist){     
          
      MetadataService metaService = GetMetadataService();     
        
      RetrieveAttributeRequest request = new RetrieveAttributeRequest();     
      request.EntityLogicalName = entity;     
      request.LogicalName = picklist;     
      request.RetrieveAsIfPublished = true;     
        
      RetrieveAttributeResponse response = (RetrieveAttributeResponse)metaService.Execute(request);     
        
      PicklistAttributeMetadata listData = (PicklistAttributeMetadata)response.AttributeMetadata;     
        
      DataTable dt = new DataTable();     
      dt.Columns.Add(new DataColumn("key"));     
      dt.Columns.Add(new DataColumn("value"));     
        
      foreach (Option o in listData.Options)     
      {     
       foreach (LocLabel l in o.Label.LocLabels)     
       {    
    //select the right language.   
        if (l.LanguageCode.Value == 1033)     
        {     
         DataRow row = dt.NewRow();     
         row["key"] = o.Value.Value;     
         row["value"] = l.Label;     
         dt.Rows.Add(row);     
        }     
       }     
      }     
      return dt;     
     }   
     
     
    public static MetadataService GetMetadataService()  
        {  
     
            CrmAuthenticationToken token = new CrmAuthenticationToken();  
            token.OrganizationName = yourorganisationname;  
            token.AuthenticationType = 0;  
     
            MetadataService mdSevice = new MetadataService();  
            mdSevice.Credentials = System.Net.CredentialCache.DefaultCredentials;  
            mdSevice.Url = String.Format("http://{0}/MSCRMServices/2007/MetadataService.asmx", yourservername);  
     
            mdSevice.CrmAuthenticationTokenValue = token;  
            mdSevice.UnsafeAuthenticatedConnectionSharing = true;  
            return mdSevice;  
        }  
       
     
    Wednesday, March 11, 2009 7:41 PM