如何在我的插件 - CRM 2011上使用OrganizationServiceProxy?

Ewe*_*ews 0 plugins fetchxml dynamics-crm-2011

我需要在CRM插件中使用fetch xml,我在这里找到了一个如何做到这一点的示例:

string groupby1 = @" 
    <fetch distinct='false' mapping='logical' aggregate='true'> 
     <entity name='opportunity'>
      <attribute name='name' alias='opportunity_count' aggregate='countcolumn' />  
      <attribute name='ownerid' alias='ownerid' groupby='true' />
      <attribute name='createdon' alias='createdon' /> 
      <attribute name='customerid' alias='customerid' /> 
     </entity> 
    </fetch>";

    EntityCollection groupby1_result = orgProxy.RetrieveMultiple(new FetchExpression(groupby1));
Run Code Online (Sandbox Code Playgroud)

但是还有一些我不知道如何使用的东西,或者它在哪里使用......它的部分内容如下:

orgProxy.RetrieveMultiple(new FetchExpression(groupby1));
Run Code Online (Sandbox Code Playgroud)

我知道它是OrganizationServiceProxy的一个对象,但它在插件类中的位置是什么?我找不到.

glo*_*rob 6

尽可能以最礼貌的方式,您可能需要向后退几步才能前进.

所以要编写一个插件,你需要实现IPlugin,它只有一个方法

public void Execute(IServiceProvider serviceProvider)
Run Code Online (Sandbox Code Playgroud)

IServiceProvider是您进入CRM的窗口以及您要加入的事件的上下文.

通常,您会执行以下操作:

var context = (IPluginExecutionContext) serviceProvider.GetService(typeof (IPluginExecutionContext));
var factory = (IOrganizationServiceFactory) serviceProvider.GetService(typeof (IOrganizationServiceFactory));
var service = factory.CreateOrganizationService(context.UserId);
Run Code Online (Sandbox Code Playgroud)

在上面的例子中,service是类型IOrganizationService.这为您提供了所期望的所有方法

service.Execute(foo);
service.RetrieveMultiple(bar);
service.Update(... /* etc
Run Code Online (Sandbox Code Playgroud)

可能是值得回顾一些围绕这个导游的-正如我在前面的回答已经给这里