如何从在插件中的PartyList取得联系的GUID? [英] How to get the Contact Guids from a PartyList in a Plugin?
问题描述
我做了一个自定义活动短信的创建消息触发一个插件。
这些插件会使用第三方短信服务供应商发送实际的短信。
I'm making a plugin that triggers on the create message of a custom activity SMS. These plugin will send the actual sms using a third party sms service provider.
因此,我需要得到mobilephone号码在短信活动的收件人字段的每个联系人。这类型的字段:PartyList
Therefore i need to get the mobilephone numbers for every contact in the "To" field of the SMS activity. This is a field of type: PartyList.
我目前使用下面的代码:
I'm currently using the following code:
EntityCollection Recipients;
Entity entity = (Entity) context.InputParameters["Target"];
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
Content = entity.GetAttributeValue<String>("subject");
Recipients = entity.GetAttributeValue<EntityCollection>("to");
for (int i = 0; i < Recipients.Entities.Count; i++)
{
Entity ent= Recipients[i];
string number = ent["MobilePhone"].ToString();
}
不过,这是行不通的,我觉得耳鼻喉科变量不包含任何属性。
But this is not working, i think the ent variable contains no attributes.
我试过要么ActivityParty编码,但也没有运气。
I've tried coding with ActivityParty also but not luck either.
我希望你们有人能帮助我与这一个。
I hope someone of you can help me with this one.
谢谢!
推荐答案
下面的是我如何终于做到了:
Here's is how I finally did it:
EntityCollection Recipients;
Entity entity = (Entity) context.InputParameters["Target"];
IOrganizationServiceFactory serviceFactory
= (IOrganizationServiceFactory)serviceProvider.GetService(
typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory
.CreateOrganizationService(context.UserId);
Content = entity.GetAttributeValue<String>("subject");
Recipients = entity.GetAttributeValue<EntityCollection>("to");
for (int i = 0; i < Recipients.Entities.Count; i++)
{
ActivityParty ap = Recipients[i].ToEntity<ActivityParty>();
String contactid = ap.PartyId.Id.ToString();
Contact c = (Contact) service.Retrieve(
Contact.EntityLogicalName,
ap.PartyId.Id,
new ColumnSet(new string[]{ "mobilephone" }));
String mobilephone = c.MobilePhone;
...
}
这篇关于如何从在插件中的PartyList取得联系的GUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!