2011-08-11 2 views
-1

私のクエリは、account.name、account.account、account.parentaccountidを返します。queryexpressionとsilverlightを使用してアカウントからparentaccountidを取得する方法

私はSilverlightとCRM2011を使用しています。

今、parentaccountid属性から値を抽出する方法を見つけるのが難しいです。

私のVSプロジェクトにsilverlightextensionmethods.csファイルが含まれており、parentaccountidから値を取得するのにGetAttributeValue<Guid>("parentaccountid")を使用しています。

返される値は空です。

これを達成する方法はありますか?

他の属性値を取得できますが、アカウントのparentaccountidと連絡先のparentcustomeridが私の人生を非常に困難にしています。

コード:VALUES FORMの応答

void GetChildren_ExecuteCallBack(IAsyncResult childresult) 
     { 
      List<TreeRecord> listc = new List<TreeRecord>(); 
      try 
      { 
       OrganizationResponse childresponse = ((IOrganizationService)childresult.AsyncState).EndExecute(childresult); 
       EntityCollection childresults = (EntityCollection)childresponse["EntityCollection"]; 

       if (childresults.Entities.Count > 0) 
       { 
        TreeConfig sitm = new TreeConfig(); 
        string sdisplay = ""; 
        string[] fields = "".Split(';'); 
        string sid = ""; 
        string pid = ""; 
        foreach (Entity childentity in childresults.Entities) 
        { 
         foreach (TreeConfig sitem in Configs) 
         { 
          if (sitem.EntityName == childentity.LogicalName) 
          { 
           sitm = sitem; 
          } 
         } 

         TreeRecord childitem = new TreeRecord(); 
         string sValue = ""; 
         sdisplay = "name;accountid;parentaccountid"; 
         fields = sdisplay.Split(';'); 
         sid = "accountid"; 
         pid = "parentaccountid"; 

         int i = sdisplay.Split(';').Length; 

         for (int j = 0; j < i; j++) 
         { 
          try { sValue += childentity.GetAttributeValue<string>(fields[j]) + " "; } 
          catch (Exception ex) 
          { 
           //s = "sValue haku: " + ex.Message.ToString(); 
           //this.ReportMessage(s.ToString()); 
          } 
         } 
         childitem.Name = sValue; 


         childitem.EntityName = childentity.LogicalName; 
         childitem.Level = sitm.Level; 
         childitem.ParentEntityName = sitm.EntityName; 
         childitem.Color = sitm.Color; 
         childitem.RecordId = childentity.GetEntityId<Guid>(sid); 

         try { childitem.ParentId = childentity.GetAttributeValue<Guid>(pid); } 
         catch 
         { 
          //sb.AppendLine("guid: parentid tietoa ei löydy"); 
          //this.ReportMessage(sb.ToString()); 
         } 
         listc.Add(childitem); 

        } 

       } 
      } 
+1

コードを表示してください。 – ccellar

+0

最初に、私はQueryExpression – Jaana

+0

を作成しましたが、すでにこれを述べています。あなたの質問を編集し、あなたが参照しているコードを挿入してください。そうでなければ誰もあなたを詳細に助けることができません。 – ccellar

答えて

3

代わりの

childentity.GetAttributeValue<Guid>(pid) 
を読み取ること


string temp="name;accountid;parentaccountid"; 
string[] fields = temp.Split(';'); 
QueryExpression query = new QueryExpression() 
{ 
      EntityName = entity, 
      ColumnSet = new ColumnSet { Columns = new System.Collections.ObjectModel.ObservableCollection<string>(fields) }, 

     Criteria = new FilterExpression 
      { 
       FilterOperator = LogicalOperator.And, 
      Conditions = 
      { 
        new ConditionExpression 
        { 
           AttributeName = parentidfield, 
           Operator = ConditionOperator.Equal, 
           Values = { id } 
        } 
       } 
      } 
}; 

OrganizationRequest req = new OrganizationRequest(); 
req.RequestName = "RetrieveMultiple"; 

req["Query"] = query; 

service.BeginExecute(req, new AsyncCallback(GetChildren_ExecuteCallBack), service); 

NEXT I TY: はFIRST私はのQueryExpressionをCREATE

使用

childentity.GetAttributeValue<EntityReference>(pid) 
+0

ありがとう、それはそれを解決! – Jaana

+0

その場合は、「回答済み」と記入してください。 –

関連する問題