【发布时间】:2016-07-07 13:32:06
【问题描述】:
如何获取与当前实体关联的所有笔记的 guid 列表(或例如集合)?
我知道它以某种方式与 service.Retreive(...) 相关联,但无法生成工作代码。
附上1:
public void Execute(IServiceProvider serviceProvider)
{
Entity entity = null;
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (entity.Contains("new_parentopportunity"))
{
try
{
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
Guid projectGuid = entity.Id;
Guid oppGuid = ((EntityReference)entity["new_parentopportunity"]).Id;
for (int i = 0; i < 100; i++) //Instead of 100, I'll place obtained collection.Length
{
Entity opp = service.Retrieve("", oppGuid, new Microsoft.Xrm.Sdk.Query.ColumnSet(true)); //RETREIVE ENTITY NOTE HERE
var temop = CreateNoteAttachment(opp);
service.Create(temp);
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
private Entity CreateNoteAttachment(Entity oppNote)
{
//some code here
}
更新 1:
我也把它写在查询中,你能看看这个,是否一切都好? PasteBin
【问题讨论】:
-
你有一些代码要分享吗?你尝试过什么,你哪里出错了?
-
@Marcus,是的,我已经发布了代码。我不明白我应该投入什么 service.Retreive() 另外,我已经看到了一种通过构造查询来做到这一点的方法
-
该插件是将所有笔记从一个实体复制到另一个实体。
标签: c# plugins dynamics-crm-2011