【问题标题】:Getting error while saving the annotation entity in CRM在 CRM 中保存注释实体时出错
【发布时间】:2013-04-22 23:07:54
【问题描述】:

我正在尝试使用以下代码将注释实体保存在 CRM 2011 中:

var annotationContext = new CrmOrganizationServiceContext(crmOrganizationService);
var annotation = annotationContext.CreateEntity("annotation");
annotationContext.AddObject(annotation);
// Setting the account id.
entity.SetAttributeValue<EntityReference>("objectid", "account", "Guid of the account");    
entity.iCrmSetPropertyValue(AnnotationDefinition.ColumnsName.DocumentBody,Convert.ToBase64String(new UnicodeEncoding().GetBytes("Sample Annotation Text")));
entity.iCrmSetPropertyValue("isdocument",true);
entity.iCrmSetPropertyValue(AnnotationDefinition.ColumnsName.Mime, "text/plain");
entity.iCrmSetPickListValue(AnnotationDefinition.ColumnsName.ObjectType, 1);
entity.iCrmSetPropertyValue(AnnotationDefinition.ColumnsName.Subject, "CompanyLogo");
annotationContext.SaveChanges();

保存更改方法失败,在 crm 服务器的事件查看器中出现以下错误:

Web Service 插件在 OrganizationId 中失败:############; SdkMessageProcessingStepId: #####; EntityName:注解;阶段:30; 消息名称:创建;大会名称: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel,版本=5.0.0.0,文化=中性, PublicKeyToken=31bf3856ad364e35;班级名称: Microsoft.Crm.Extensibility.InternalOperationPlugin;例外: 未处理的异常:System.InvalidCastException:指定的演员是 无效。在 Microsoft.Crm.BusinessEntities.EntityNameReferenceAttributeConverter.ConvertToBusinessEntity(对象 值,AttributeMetadata attributeMetadata,字典`2 abbrvToChildAttributeMetadata,ICrmConversionContext 上下文, BusinessEntity 目标)在 Microsoft.Crm.BusinessEntities.EntityToBusinessEntityConverter.ConvertUsingExistingBusinessEntity(EntityMetadata entityMetadata、ICrmConversionContext 转换上下文、实体 实体,BusinessEntity businessEntity)在 Microsoft.Crm.BusinessEntities.BusinessEntity.Converter.ConvertFrom(ITypeDescriptorContext 上下文,CultureInfo 文化,对象值)在 Microsoft.Crm.BusinessEntities.ConversionHelpers.Convert(ICrmConversionContext 转换上下文,对象源,类型destinationType)在 Microsoft.Crm.Extensibility.DictionaryMapper.Map(ParameterCollection 输入,ICrmConversionContext 上下文)在 Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider 服务提供商)在 Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext 上下文)在 Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext 上下文)

【问题讨论】:

  • 你有类型冲突:System.InvalidCastException: Specified cast is not valid
  • 您是在发送"Guid of the account" 还是只是为了演示目的?

标签: dynamics-crm-2011


【解决方案1】:

您将annotation 变量添加到上下文中,但更新了实体对象。

【讨论】:

    猜你喜欢
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 2021-07-17
    • 2020-08-20
    • 2012-10-01
    相关资源
    最近更新 更多