2016-06-26 4 views
1

カスタムアクティビティSMSの作成メッセージでトリガするWindowsサービスを作成しています。これらのプログラムは、サードパーティのSMSサービスプロバイダを使用して実際のSMSを送信します。パーティーリストからGUIDと携帯電話を取得するには?

したがって、私はSMSアクティビティの "To"フィールドにすべての連絡先/リード/ユーザー/アカウントの携帯電話番号を取得する必要があります。これはタイプのフィールドです:パーティリスト。また

私はフィールド空である「ために、」あれば私はそれを使用する別のフィールド(「new_msisdn」)を持っている。(このフィールドでは、ユーザが直接電話番号を入力します)

私は現在、次のコードを使用しています:

EntityCollection results = CrmService.RetrieveMultiple(query);   
string msisdn; 
string newmessage; 
Entity entity; 
int encode; 
bool flash; 
res = new Message[results.Entities.Count]; 
if (results != null && results.Entities.Count > 0) 
{     
    try 
     { 
     for (int i = 0; i < results.Entities.Count; i++) 
      { 
      entity = results.Entities[i]; 
       msisdn = (string)entity["new_msisdn"]; 
// I have to add an condition here to check if "to" is not empty , then get mobilephones. 
       newmessage = (string)entity["new_message"]; 
       encode = ((OptionSetValue)entity["new_messagetype"]).Value; 
       flash = (bool)entity["new_flashsms"]; 
       res[i] = new Message(); 
       res[i].crmId = entity.Id; 
       res[i].senderNumber = msisdn; 
       res[i].sendDate = DateTime.Now; 
       res[i].message = newmessage; 
       if (encode == 1) 
       res[i].encoding = 1; 
       else 
       res[i].encoding = 2; 
       if (flash) 
       res[i].flash = 2; 
       else res[i].flash = 1; 
      } 
     } 

私はこれを行うためのアイデアはありません。ちなみに、私はCRM 2015を使用しています。

答えて

0

以下のようなものを使用してみてください。

if(entity.Attributes.Contains("to")) 
{ 
EntityCollection to=(EntityCollection)entitiy["to"]; 
foreach(Entity toEntity in to.Entities) 
    { 
    //You will get each to field record here. 
    //Use that information to get the mobile numbers of respective users. 
    Guid Id=toEntity.Id; 
    //Below code mostly will return string.empty. 
    //You may have to query CRM to get mobile number for respective contacts. 
    string mobileNumber=toEntity.Attributes.Contains("mobilenumber")?toEntity["mobilenumber"].ToString():string.Empty; 
    } 
} 

私はあなたの質問に対処しました。同じことについてさらにご質問がありましたらお知らせください。

また、特定の属性を使用する前に、属性が既にエンティティオブジェクトで使用可能かどうかを確認することをお勧めします。

+0

ありがとうございます。しかし、エンティティの名前とそのGUIDを含むエンティティ参照を使用する方が良いことがわかった – Farhad

+0

ファハド、私はあなたがGuidとMobileNumberを取得したいと思った。あなたが名前を望むなら、Entity Objectもその属性を持つことができます。エンティティコレクション内のデータを取得し、さらにそのデータを使用するというアプローチの上で答えようとしました。 Entity Referenceは、GUIDを取得するための別のオプションです。しかし、携帯電話番号では、このguidと論理名を使用して再度データベースにアクセスする必要があります。あなたはすでにエンティティのコレクションを持っているので、なぜあなたはそれを再利用できません。これは、不必要なDBヒットを回避します。 – Renjith

+0

本当にありがとうRenjith。あなたの答えは私に道を示す。あなたが正しいというところで、両方の解決策は正しいですが、あなたの負担は少なくなります。 – Farhad

関連する問題