积极答复者
编写PlugIn时,能一下查询2个实体吗?急!

问题
-
public void Execute(IPluginExecutionContext context)
{
ICrmService crmService = context.CreateCrmService(false);
task calltask = (task)crmService.Retrieve(EntityName.task.ToString(), context.UserId, new ColumnSet(new string[] { "subject","description" }));
systemuser callingUser = (systemuser)crmService.Retrieve(EntityName.systemuser.ToString(), context.UserId, new ColumnSet(new string[] { "domainname" }));
this.AddWorkjour(this.GetIdByName(callingUser.domainname.ToString()), calltask.subject.ToString(), calltask.description.ToString());
}
大家帮我看看,我现在想在创建活动的任务(task)时,执行 以上操作,需要2个实体的数据(systemuser,task),但是我写好后,注册的时候,有First primiarykey我选择了Task SeconPrimaryKey我想选择systemuser,可是不让选了,我不知道该怎么操作 才能实现我的操作呢??
梅小虎
答案
-
task calltask = (task)crmService.Retrieve(EntityName.task.ToString(), context.UserId, new ColumnSet(new string[] { "subject","description" }));
你这个是错的,你Retrieve的是task,但是传过去的guid却是当前用户的guid,你plugin注册到task,那你可以通过target来获取task的属性值
用户你就必须通过retrieve来获取属性值
systemuser user = (systemuser)crmService.Retrieve(EntityName.systemuser.ToString(), context.UserId, new ColumnSet(new string[] { "domainname","username" }));
Batistuta Cai-刀客 | 蔡敏生 | MS CRM MVP | Blog:http://caims.cnblogs.com -
DynamicEntity taskTarget = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
Batistuta Cai-刀客 | 蔡敏生 | MS CRM MVP | Blog:http://caims.cnblogs.com -
获取属性值:
string description = (String)taskTarget .Properties["description"];
string subject = (String)taskTarget .Properties["subject"];
Batistuta Cai-刀客 | 蔡敏生 | MS CRM MVP | Blog:http://caims.cnblogs.com
全部回复
-
-
task calltask = (task)crmService.Retrieve(EntityName.task.ToString(), context.UserId, new ColumnSet(new string[] { "subject","description" }));
你这个是错的,你Retrieve的是task,但是传过去的guid却是当前用户的guid,你plugin注册到task,那你可以通过target来获取task的属性值
用户你就必须通过retrieve来获取属性值
systemuser user = (systemuser)crmService.Retrieve(EntityName.systemuser.ToString(), context.UserId, new ColumnSet(new string[] { "domainname","username" }));
Batistuta Cai-刀客 | 蔡敏生 | MS CRM MVP | Blog:http://caims.cnblogs.com -
DynamicEntity taskTarget = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
Batistuta Cai-刀客 | 蔡敏生 | MS CRM MVP | Blog:http://caims.cnblogs.com -
获取属性值:
string description = (String)taskTarget .Properties["description"];
string subject = (String)taskTarget .Properties["subject"];
Batistuta Cai-刀客 | 蔡敏生 | MS CRM MVP | Blog:http://caims.cnblogs.com -
DynamicEntity taskTarget = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
string description = (String)taskTarget .Properties["description"];
string subject = (String)taskTarget .Properties["subject"];
如果我选择注册的是Task ParameterName需要做什么更改不? 是不是上面这些就够了?
梅小虎