Crm 如何从派对列表中获取guid和mobilephone?

Crm 如何从派对列表中获取guid和mobilephone?,crm,Crm,我正在制作一个windows服务,该服务在自定义活动SMS的创建消息上触发。这些程序将使用第三方sms服务提供商发送实际的sms 因此,我需要在SMS活动的“收件人”字段中获取每个联系人/潜在客户/用户/帐户的手机号码。这是一个类型为“参与方列表”的字段 此外,我还有另一个字段(“newmsisdn”),如果“to”字段为空,我将使用它。(在此字段中,用户将直接键入电话号码) 我目前正在使用以下代码: EntityCollection results = CrmService.Retriev

我正在制作一个windows服务,该服务在自定义活动SMS的创建消息上触发。这些程序将使用第三方sms服务提供商发送实际的sms

因此,我需要在SMS活动的“收件人”字段中获取每个联系人/潜在客户/用户/帐户的手机号码。这是一个类型为“参与方列表”的字段

此外,我还有另一个字段(“newmsisdn”),如果“to”字段为空,我将使用它。(在此字段中,用户将直接键入电话号码)

我目前正在使用以下代码:

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;
            }
        }
EntityCollection结果=CrmService.RetrieveMultiple(查询);
字符串msisdn;
字符串newmessage;
实体;
整数编码;
布尔闪光;
res=新消息[results.Entities.Count];
if(results!=null&&results.Entities.Count>0)
{                
尝试
{
对于(int i=0;i

我不知道该怎么做。顺便说一句,我用的是CRM 2015。

试着用下面的方法

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;
  }
 }
希望我已经回答了您的问题。如果您还有其他问题,请告诉我们


此外,在使用特定属性之前,最好检查实体对象中的属性是否已可用。

尝试使用下面的方法

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;
  }
 }
希望我已经回答了您的问题。如果您还有其他问题,请告诉我们


另外,在使用特定属性之前,最好先检查实体对象中的属性是否已可用。

谢谢您的回答。但我发现最好使用实体引用,其中包括实体名称及其GUIDFarhad,我认为您需要获取Guid和MobileNumber。如果您需要名称Entity对象也可以具有该属性。我尝试在您获取实体集合中的数据然后进一步使用该数据的方法的基础上进行回答。实体引用也是获取guid的另一个选项。但是对于移动电话号码,您可能必须使用此guid和逻辑名称再次访问数据库。因为您已经有了实体集合为什么你不能重用它。这将避免不必要的数据库命中。非常感谢你的Renjith。你的答案为我指明了方向。顺便说一句,你是对的,两种解决方案都是正确的,但是你的解决方案会导致较少的命中。谢谢你的回答。但是我发现最好使用实体引用,其中包括实体的名称及其GUIDFarhad,我以为您想要获取Guid和MobileNumber。如果您想要名称实体对象也可以具有该属性。我尝试在您获取实体集合中的数据然后进一步使用该数据的方法的基础上进行回答。实体引用也是获取Guid的另一个选项。但对于移动电话号码,您可能没有o使用此guid和逻辑名称再次命中数据库。既然您已经有一个实体集合,为什么不能重用它。这将避免不必要的数据库命中。非常感谢Renjith。您的回答为我指明了方向。顺便说一句,两种解决方案都是正确的,但您的解决方案命中率会降低。