简体   繁体   English

CRM 2011插件-查询与数组中的值匹配的记录

[英]CRM 2011 Plugin - Query records that match a value within an array

I just discovered this great site and would like to thank everyone in advance for any help. 我刚刚发现了这个很棒的网站,并在此先感谢大家的帮助。

I am working on a plugin that would update contact's email address where the contact's email matches one of the emails in an array. 我正在使用一个插件来更新联系人的电子邮件地址,该联系人的电子邮件与数组中的一封电子邮件相匹配。 We use a 3rd party marketing tool for sending out mass email campaigns. 我们使用第三方营销工具来发送大量电子邮件活动。 We want to take all the soft bounce emails we have and update the CRM and clear the bad email from the system. 我们希望接收所有已收到的软反弹电子邮件,并更新CRM并从系统中清除不良电子邮件。 I have an idea to create a plugin where I declare a string array of all the email addresses that bounced. 我有一个创建插件的想法,在该插件中声明一个被退回的所有电子邮件地址的字符串数组。 Then run a query of contacts where the email address matches any one of the values in the array. 然后运行联系人查询,其中电子邮件地址与数组中的任何值匹配。 If it matches I would simple update the email address field. 如果匹配,我将简单地更新电子邮件地址字段。 Is something like this possible? 这样的事情可能吗?

I know how to set up the array and query records but what I can't seem to find an example of is where the query looks for the contact email address to match any one of the values in the array. 我知道如何设置数组和查询记录,但是我似乎找不到一个示例,该查询在其中查找联系人电子邮件地址以匹配数组中的任何值。 I only find examples where it looks for a specific value from within the array, like 'contact.emailaddress = "name@email.com"'. 我只找到从数组中查找特定值的示例,例如“ contact.emailaddress =“ name@email.com””。

Thanks again for any help. 再次感谢任何帮助。

It's possible yes, but you will have to step through the entire array. 可能是的,但是您将必须遍历整个阵列。

So 1st part: I assume you know how to identify that array inside the plugin. 因此,第1部分:我假设您知道如何在插件中识别该数组。

2nd part: you already know how to query the Contact entity for a specific e-mail address 第二部分:您已经知道如何查询联系人实体以获取特定的电子邮件地址

3rd part: Just repeat the example you found to find contact.emailaddress = "name@email.com" for each item in the array of e-mail addresses you have. 第三部分:只需重复您发现的示例,即可为您拥有的电子邮件地址数组中的每个项目找到contact.emailaddress =“ name@email.com”。

foreach (string email in emailAddressArrayFrom3rdPartyTool)
{
    //Query for the contacts that match that e-mail address here
    //Update Contacts so that the e-mail address is removed.
}

You can also define a List and populate it with Contacts you want to update it. 您还可以定义一个列表,并在列表中添加要更新的联系人。 Then you can call the updates when you have tracked down all the records. 然后,您可以在跟踪所有记录时调用更新。

Update: You can also go the Fetch XML route: (more info here: http://msdn.microsoft.com/en-us/library/gg328117.aspx ) 更新:您也可以采用Fetch XML路线:(更多信息,请参见: http : //msdn.microsoft.com/en-us/library/gg328117.aspx

string fetch = @"
   <fetch mapping='logical'>
     <entity name='contact'> 
        <attribute name='contactId'/> 
           <filter> 
              <condition attribute='emailaddress' operator='in'>
                    <value>List of Array emails here</value>
                    <value>List of Array emails here</value>
                    <value>List of Array emails here</value>
                </condition>
           </filter> 
     </entity> 
   </fetch> "; 

EntityCollection result = _serviceProxy.RetrieveMultiple(new FetchExpression(fetch));

foreach (var c in result.Entities)
   {
   System.Console.WriteLine(c.Attributes["name"]);
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM