问题描述
我正在 postOperation 同步执行一个插件.我使用 IOrganizationService.Create
创建了一个实体.这有效,我得到了一个 GUID,我可以看到该记录存在于 CRM 中.在此之后,我尝试使用相同的 IOrganizationService 和创建调用返回的 GUID 检索相同的记录:
I am executing a plugin synchronously postOperation.I create an entity using IOrganizationService.Create
. This works, I get a GUID and I can see that the record exists in the CRM.Right after this, I am trying to retrieve the same record using same IOrganizationService and the GUID returned by the create call:
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
tracer.Trace("context is " + context.InputParameters["Target"]);
context.OutputParameters["Message"] = "in plugin";
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)
{
/* some other processing here
.
.
*/
Guid polId = service.Create(policy);
Entity polEntity = service.Retrieve("new_customEntiry", polId, new ColumnSet(true));
但是 polEntity.Id
为空.polEntity["someattribute"]
也是 null .
But the polEntity.Id
is null. polEntity["someattribute"]
is also null .
为什么检索调用不起作用?我错过了什么?
Why is the retrieve call not working? What am I missing?
相关帖子:Id =xxxxxx"的错误帐户;不存在
推荐答案
我确信代码中存在您没有分享的问题.
I am sure there are issues in code which you didn't share.
可能的根本原因:
service.Create(policy)
中用于策略对象的实体应与 service.Retrieve
中使用的 new_customEntiry
相同,检查它
The entity used for policy object in service.Create(policy)
should be same as new_customEntiry
which used in service.Retrieve
, check it
建议:
1.添加跟踪日志以记录插件跟踪或配置文件/调试中的polId
以查看
2.尝试异步模式&测试相同的插件步骤
3.不要检索整个实体对象,而是这样做
1.Add a trace log to log the polId
in plugin trace or profile/debug it to see
2.Try asynchronous mode & test the same plugin step
3.Don't retrieve the whole entity object, instead do this
Guid polId = service.Create(policy);
Entity toUpdate = new Entity("new_entityToUpdate", entityToUpdateId);
toUpdate["new_customEntiryId"] = new EntityReference("new_customEntiry", polId);
service.Update(toUpdate);
这篇关于错误:在插件中创建后无法检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!