2014-07-13 69 views
0

我需要一個給定實體(multiform)的所有表單的列表;我知道客戶端Javascript代碼的解決方案,但我使用服務器端代碼。MSCRM,檢索實體表單列表

我嘗試使用此消息得到實體的元數據,但我不能找到它:

RetrieveEntityRequest mdRequest = new RetrieveEntityRequest() 
    { 
     EntityFilters = EntityFilters.All, 
     LogicalName = entityName, 
     RetrieveAsIfPublished = false 
    }; 

我試着檢索實體FormXML,但它不存在或者:

private string GetFormXML(int objectTypeCode) 
{ 
     QueryExpression q = new QueryExpression("systemform"); 
     q.ColumnSet = new ColumnSet("formxml"); 
     q.Criteria.AddCondition(new ConditionExpression("type", ConditionOperator.Equal, 2)); 
     q.Criteria.AddCondition(new ConditionExpression("objecttypecode", ConditionOperator.Equal, objectTypeCode)); 

     var entities = ctx.OrganizationService.RetrieveMultiple(q); 

     if (entities != null) 
     { 
      return entities.Entities.First().Attributes["formxml"].ToString(); 
     } 
     else 
     { 
      return ""; 
     } 
} 

任何建議?

回答

0

我認爲systemform實體具有objecttypecode作爲字符串,它接受實體名稱而不是真正的實體對象類型代碼。你可以嘗試改變對象類型代碼從數字到實體名稱?

private string GetFormXML(int objectTypeCode) 
{ 
     QueryExpression q = new QueryExpression("systemform"); 
     q.ColumnSet = new ColumnSet("formxml"); 
     q.Criteria.AddCondition(new ConditionExpression("type", ConditionOperator.Equal, 2)); 
     q.Criteria.AddCondition(new ConditionExpression("objecttypecode", ConditionOperator.Equal, "contact")); 

     var entities = ctx.OrganizationService.RetrieveMultiple(q); 

     if (entities != null) 
     { 
      return entities.Entities.First().Attributes["formxml"].ToString(); 
     } 
     else 
     { 
      return ""; 
     } 
} 
+0

我有檢索FormXml沒問題,我無法找到我所期待的在那裏。 我在找formid description – user3303301

+0

你試過嗎? queryExpression.ColumnSet = new ColumnSet(「formxml」,「formid」,「description」); –

0
 public Dictionary<Guid, string> GetNevegationItems(int objectTypeCode) 
    { 
     QueryExpression q = new QueryExpression("systemform"); 
     q.ColumnSet = new ColumnSet("name", "formid"); 
     q.Criteria.AddCondition(new ConditionExpression("type", ConditionOperator.Equal, 2)); 
     q.Criteria.AddCondition(new ConditionExpression("objecttypecode", ConditionOperator.Equal, objectTypeCode)); 

     var entities = ctx.OrganizationService.RetrieveMultiple(q); 

     if (entities != null) 
     { 
      Dictionary<Guid, string> rslt = new Dictionary<Guid, string>(); 
      foreach (var item in entities.Entities) 
      { 
       rslt.Add(item.GetAttributeValue<Guid>("formid"), item.GetAttributeValue<string>("name")); 
      } 
      return rslt; 
     } 
     else 
     { 
      return null; 
     } 
    }