-3
我有一個任務,在crm 4中創建一個插件,該插件應該1.在電子郵件的主題字段中輸入帳戶的名稱,然後2.放入帳戶的聯繫人列表到電子郵件的cc字段。 我做的第一件事,它的工作,但第二... ...沒有這麼多... 我已經看到一些樣品,但沒有一個接近halp我... 我想幫助和解釋如何查找屬於該帳戶的聯繫人列表,然後將該列表放入cc字段。 這裏是開始時...:把帳戶的聯繫人列表放在電子郵件的cc字段中
namespace mail
{
public class Class1 : IPlugin
{
public void Execute(IPluginExecutionContext context)
{
DynamicEntity entity = null;
if (context.InputParameters.Properties.Contains("Target") &&
context.InputParameters.Properties["Target"] is DynamicEntity)
{
entity = (DynamicEntity)context.InputParameters.Properties["Target"];
if (entity.Name != EntityName.account.ToString())
{
return;
}
}
else
{
return;
}
try
{
// updating the subject of the email
ICrmService service = context.CreateCrmService(true);
account accountRecord = (account)service.Retrieve("account", ((Key)entity.Properties["accountid"]).Value, new ColumnSet(new string[] { "name" }));
String str = String.Empty;
str = accountRecord.name.ToString();
DynamicEntity followup = new DynamicEntity();
followup.Name = EntityName.email.ToString();
followup.Properties = new PropertyCollection();
followup.Properties.Add(new StringProperty("subject", str));
//updating the CC of the email
TargetCreateDynamic targetCreate = new TargetCreateDynamic();
targetCreate.Entity = followup;
CreateRequest create = new CreateRequest();
create.Target = targetCreate;
CreateResponse created = (CreateResponse)service.Execute(create);
}
catch
{
throw new InvalidPluginExecutionException(
"An error occurred in the AccountUpdateHandler plug-in.");
}
}
}
}