Visual studio 2010 VS2010插件-错误1当前上下文中不存在名称“ExecutePostAccountUpdate”
我正在尝试制作一个插件,从商机中获取收入,并将账户实体的收入合计起来。我正在使用Visual Studio 2010 Professional和MS Dynamics CRM 2013 SDK。我一直在遵循两个指南来帮助我到达那里,但它们是为Dynamics CRM 2011提供的。CRM 2013的指南并不多,所以我希望使用这个CRM 2011指南来启动一个基本插件,并根据我的需要修改它 1: 2: 使用这些示例,我在VisualBasic2010上启动了插件,但在构建/部署时出现了一些错误。错误1是一个我似乎无法克服的错误 1-找不到类型或命名空间名称“FetchExpression”是否缺少using指令或程序集引用?C:\VS2010\AccountRevenue\Plugins1\PostAccountUpdate.cs 114 95 Plugins1 2-找不到类型或命名空间名称“FetchExpression”是否缺少using指令或程序集引用?C:\VS2010\AccountRevenue\Plugins1\PostAccountUpdate.cs 114 99 Plugins1 3-当前上下文C:\VS2010\AccountRevenue\Plugins1\PostAccountUpdate.cs 51 154 Plugins1中不存在名称“ExecutePostAccountUpdate”Visual studio 2010 VS2010插件-错误1当前上下文中不存在名称“ExecutePostAccountUpdate”,visual-studio-2010,plugins,crm,Visual Studio 2010,Plugins,Crm,我正在尝试制作一个插件,从商机中获取收入,并将账户实体的收入合计起来。我正在使用Visual Studio 2010 Professional和MS Dynamics CRM 2013 SDK。我一直在遵循两个指南来帮助我到达那里,但它们是为Dynamics CRM 2011提供的。CRM 2013的指南并不多,所以我希望使用这个CRM 2011指南来启动一个基本插件,并根据我的需要修改它 1: 2: 使用这些示例,我在VisualBasic2010上启动了插件,但在构建/部署时出现了一些错误。
`// <copyright file="PostAccountUpdate.cs" company="">
// Copyright (c) 2014 All Rights Reserved
// </copyright>
// <author></author>
// <date>2/7/2014 2:53:23 PM</date>
// <summary>Implements the PostAccountUpdate Plugin.</summary>
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
// </auto-generated>
using Microsoft.Xrm.Sdk.Client; // to get the OrganizationContext
using System.Linq; // to use linq queries with OrganizationContext
namespace AccountRevenue.Plugins1
{
using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
/// <summary>
/// PostAccountUpdate Plugin.
/// Fires when the following attributes are updated:
/// All Attributes
/// </summary>
public class PostAccountUpdate: Plugin
{
/// <summary>
/// Alias of the image registered for the snapshot of the
/// primary entity's attributes before the core platform operation executes.
/// The image contains the following attributes:
/// rrm_accountrevenue
/// </summary>
private readonly string preImageAlias = "PreImage";
/// <summary>
/// Alias of the image registered for the snapshot of the
/// primary entity's attributes after the core platform operation executes.
/// The image contains the following attributes:
/// rrm_accountrevenue
///
/// Note: Only synchronous post-event and asynchronous registered plug-ins
/// have PostEntityImages populated.
/// </summary>
private readonly string postImageAlias = "PostImage";
/// <summary>
/// Initializes a new instance of the <see cref="PostAccountUpdate"/> class.
/// </summary>
public PostAccountUpdate()
: base(typeof(PostAccountUpdate))
{
base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "account", new Action<LocalPluginContext>(ExecutePostAccountUpdate)));
// Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.
// You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.
}
/// <summary>
/// Executes the plug-in.
/// </summary>
/// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
/// <see cref="IPluginExecutionContext"/>,
/// <see cref="IOrganizationService"/>
/// and <see cref="ITracingService"/>
/// </param>
/// <remarks>
/// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
/// The plug-in's Execute method should be written to be stateless as the constructor
/// is not called for every invocation of the plug-in. Also, multiple system threads
/// could execute the plug-in at the same time. All per invocation state information
/// is stored in the context. This means that you should not use global variables in plug-ins.
/// </remarks>
protected void ExecutePostOpportunityCreate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
IPluginExecutionContext context = localContext.PluginExecutionContext;
//Get a IOrganizationService
IOrganizationService service = localContext.OrganizationService;
//create a service context
var ServiceContext = new OrganizationServiceContext(service);
//ITracingService tracingService = localContext.TracingService;
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parmameters.
Entity entity = (Entity)context.InputParameters["Target"];
//get the customerid
EntityReference a = (EntityReference)entity.Attributes["customerid"];
decimal totalAmount = 0;
try
{
//fetchxml to get the sum total of rrm_accountrevenue
string rrm_accountrevenue_sum = string.Format(@"
<fetch distinct='false' mapping='logical' aggregate='true'>
<entity name='opportunity'>
<attribute name='rrm_accountrevenue' alias='rrm_accountrevenue_sum' aggregate='sum' />
<filter type='and'>
<condition attribute='statecode' operator='eq' value='Open' />
<condition attribute='customerid' operator='eq' value='{0}' uiname='' uitype='' />
</filter>
</entity>
</fetch>", a.Id);
EntityCollection rrm_accountrevenue_sum_result = service.RetrieveMultiple(new FetchExpression(rrm_accountrevenue_sum));
foreach (var c in rrm_accountrevenue_sum_result.Entities)
{
totalAmount = ((Money)((AliasedValue)c["rrm_accountrevenue_sum"]).Value).Value;
}
//updating the field on the account
Entity acc = new Entity("account");
acc.Id = a.Id;
acc.Attributes.Add("new_oppamount", new Money(totalAmount));
service.Update(acc);
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
}
}
`
1,2-您需要添加对microsoft.xrm.sdk.dll和microsoft.crm.sdk.proxy.dll的引用。 您可以在SDK中找到该dll 3-您可以重载Execute方法
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
}