我正在尝试为 Microsoft Dynamics CRM 2011 编写自定义工作流作为培训练习。我使用的代码如下,它适用于标准插件,但是当作为自定义工作流的一部分运行时,给了我一个字典错误中不存在的键。任何人都可以发现任何原因吗?我检查了所有正确的实体和字段名称。
谢谢
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Collections.ObjectModel;
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;
using System.Diagnostics;
namespace TestWflow
{
public class SampleCustomActivity : CodeActivity
{
protected override void Execute(CodeActivityContext executionContext)
{
//Activity code
// Get the context service.
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
// Use the context service to create an instance of IOrganizationService.
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);
if (context.Depth == 1)
{
Entity targetCont = null;
targetCont = (Entity)context.InputParameters["Target"];
Guid contID = targetCont.Id;
ColumnSet contCols = new ColumnSet("jobtitle");
targetCont = service.Retrieve("contact", contID, contCols);
targetCont.Attributes["jobtitle"] = "test jobtitle here";
service.Update(targetCont);
}
}
}
}