首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CRM 2015自定义工作流活动,获取错误:该实体是只读的,“Id”属性不能修改

CRM 2015自定义工作流活动,获取错误:该实体是只读的,“Id”属性不能修改
EN

Stack Overflow用户
提问于 2016-02-26 15:25:44
回答 1查看 847关注 0票数 2

我有问题,使一个自定义的工作流活动的工作。我已经将其简化为最简单的代码:

代码语言:javascript
复制
// TODO: Implement your custom Workflow business logic.

// Get the context
var xrmContext = new OrganizationServiceContext(service);

// Get an object that we can update
var client = (from a in xrmContext.CreateQuery("account")
    where a.GetAttributeValue<Guid>("accountid") == new Guid("bfa273d1-d34c-e511-80cc-00155d021c08")
    select a).Single();

// Make a change
client.Attributes["name"] = "Gray Test A - CHANGED";

// Write it out
xrmContext.UpdateObject(client);
xrmContext.SaveChanges();

如果您已经创建了一个工作流,那么您将看到它并没有变得比这简单得多:

  • 获取上下文
  • 取得帐户记录
  • 做最简单的改变
  • 更新并保存。

我在跟踪日志中得到以下错误:

代码语言:javascript
复制
[2016-02-26 15:15:09.328] Process:CrmAsyncService |Organization:00000000-0000-0000-0000-000000000000 |Thread:   36 |Category: Platform |User: 00000000-0000-0000-0000-000000000000 |Level: Error |ReqId: 00000000-0000-0000-0000-000000000000 | ExceptionConverter.ConvertMessageAndErrorCode  ilOffset = 0x23B
>   System.InvalidOperationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #5CC91FB6: System.InvalidOperationException: The entity is read-only and the 'Id' property cannot be modified. Use the context to update the entity instead.
>   at Microsoft.Xrm.Sdk.Entity.set_Id(Guid value)
>   at Microsoft.Crm.Extensibility.ProxyPluginExecutionContext.CopyModifiedEntityAttributes(PipelineConversionContext context, Entity originalEntity, Entity newEntity)
>   at Microsoft.Crm.Extensibility.ProxyPluginExecutionContext.ConvertPropertyBagToParameterCollection(PipelineExecutionContext context, PropertyBag propertyBag, ParameterCollection originalParameterCollection)
>   at Microsoft.Crm.Extensibility.ProxyPluginExecutionContext.Dispose(Boolean disposing)
>   at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.GetImages(PipelineExecutionContext context, Object pluginDefinition)
>   at Microsoft.Crm.Extensibility.ImageRetrievalStep.MergeEntityRequests(PipelineExecutionContext context, Dictionary`2 entityRequests)
>   at Microsoft.Crm.Extensibility.ImageRetrievalStep.Execute(PipelineExecutionContext context)
>   at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action)
>   at Microsoft.Crm.Extensibility.Pipeline.Execute(PipelineExecutionContext context)
>   at Microsoft.Crm.Extensibility.MessageProcessor.<>c__DisplayClass1.<RunStage>b__0()
>   at Microsoft.Crm.Extensibility.PipelineInstrumentationHelper.Execute(Boolean instrumentationEnabled, String stopwatchName, ExecuteWithInstrumentation action)
>   at Microsoft.Crm.Extensibility.MessageProcessor.RunStage(PipelineExecutionContext context, Int32 pipelineStage)
>   at Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext context)
>   at Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext context)
>   at Microsoft.Crm.Extensibility.ExternalMessageDispatcher.ExecuteInternal(IInProcessOrganizationServiceFactory serviceFactory, IPlatformMessageDispatcherFactory dispatcherFactory, String messageName, String requestName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, ParameterCollection fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId, Guid transactionContextId, Int32 invocationSource, Nullable`1 requestId, Version endpointVersion)
>   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequestRequestWithInstrumentation(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, UserAuth userAuth, Guid targetUserId, OrganizationContext context, Boolean returnResponse, Boolean checkAdminMode, Object operation)
>   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, UserAuth userAuth, Guid targetUserId, OrganizationContext context, Boolean returnResponse, Boolean checkAdminMode)
>   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode)
>   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode)

我不明白为什么我不能做这个最简单的操作。

有人能给我点光吗?谢谢你,格雷

EN

回答 1

Stack Overflow用户

发布于 2016-03-14 15:03:14

尝试将记录附加到保存之前的上下文,如下所示:

代码语言:javascript
复制
xrmContext.ClearChanges();
if (!xrmContext.IsAttached(client)) xrmContext.Attach(client);
xrmContext.UpdateObject(client);
xrmContext.SaveChanges();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35655561

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档