如果实体是品牌 new/temporary,如何将实体发送到全局操作输入参数?
How to send an entity to a global action input parameter if the Entity is brand new/temporary?
我认为这个问题与此处链接的问题不同:
我有一个接受 ClubOfficer
实体作为必需输入参数的全局操作。这是我的代码生成的有效负载示例:
{
"ClubOfficer":{
"_ti_club_officer_code_value":"6efab90f-7d2b-e811-a957-000d3a34a108",
"ti_club_id":{
"accountid":"cbf646cb-a232-e811-a959-000d3a34a0aa"
},
"ti_member":{
"contactid":"e318472c-c732-e811-a959-000d3a34ae50"
},
"ti_start_date":"2018-07-01T00:00:00Z",
"ti_end_date":"2018-12-31T23:59:59Z"
},
"Term":"Current"
}
但是,甚至在调用该操作之前,它就失败并显示错误:
{
"error": {
"code": "0x0",
"message": "CRM do not support direct update of Entity Reference properties, Use Navigation properties instead.",
"innererror": {
"message": "CRM do not support direct update of Entity Reference properties, Use Navigation properties instead.",
"type": "Microsoft.Crm.CrmHttpException",
"stacktrace": " at Microsoft.Crm.Extensibility.OData.TypeConverters.EntityReferenceAttributeTypeConverter.ConvertToCrmTypeInternal(Guid edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmTypeConverterBase`2.ConvertToCrmType(Object edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmEntityTypeConverter.SetStructuralPropertyToXrmEntity(Entity entity, EntityMetadata entityMetadata, String crmAttributeName, IEdmProperty edmProperty, Object propertyValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmEntityTypeConverter.ConvertToCrmTypeInternal(EdmEntityObject edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmTypeConverterBase`2.ConvertToCrmType(Object edmTypeValue)\r\n at Microsoft.Crm.Extensibility.ODataV4.Converters.TypeConverters.OnDemandEdmEntityTypeConverter.ConvertToCrmTypeInternal(EdmEntityObject edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmTypeConverterBase`2.ConvertToCrmType(Object edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.RequestResponseConverter.AddSDKRequestParameterFromEdmOperationParameter(IEdmModel edmModel, IEdmOperation edmOperation, ParameterCollection parameterCollection, KeyValuePair`2 parameter, Tuple`2 messagePair)\r\n at Microsoft.Crm.Extensibility.OData.RequestResponseConverter.GetRequestParamsFromOperationRequest(IEdmModel edmModel, IEdmOperation edmOperation, Dictionary`2 parameters, Dictionary`2 boundParameters, Tuple`2 messagePair, Dictionary`2 offlineData)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.ExecuteOperation(CrmODataExecutionContext context, EdmOperation edmOperation, Dictionary`2 parameters, Dictionary`2 boundParameters)\r\n at Microsoft.Crm.Extensibility.OData.ActionController.ProcessOperationRequest(String operationName, Dictionary`2 operationParameters, EntityReference entityReference, String boundEntityName, String boundEntityType)\r\n at Microsoft.Crm.Extensibility.OData.ActionController.<>c__DisplayClass9_0.<PostUnboundAction>b__0()\r\n at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)\r\n at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
ClubOfficer 不是现有实体,但我希望 Action 将其视为 ClubOfficer 临时实体,以便我可以利用实体属性的 "type safety"。那可能吗?或者我是否必须将 ClubOfficer 作为字符串参数传递,然后对 JSON 字符串进行操作?这个错误是什么意思,我该如何解决?
很遗憾,这是不可能的。您没有将整个实体传递给操作,您只是传递了实体引用,它只是实体的名称及其 ID。所以你无论如何都不能传递额外的值。
执行此操作的正确方法是为每个输入创建额外的输入参数。这样它们将是强类型的。另一种选择是传递一个 JSON 字符串有效负载,您使用自定义 activity.
解析该字符串有效负载
希望对您有所帮助!
我认为这个问题与此处链接的问题不同:
我有一个接受 ClubOfficer
实体作为必需输入参数的全局操作。这是我的代码生成的有效负载示例:
{
"ClubOfficer":{
"_ti_club_officer_code_value":"6efab90f-7d2b-e811-a957-000d3a34a108",
"ti_club_id":{
"accountid":"cbf646cb-a232-e811-a959-000d3a34a0aa"
},
"ti_member":{
"contactid":"e318472c-c732-e811-a959-000d3a34ae50"
},
"ti_start_date":"2018-07-01T00:00:00Z",
"ti_end_date":"2018-12-31T23:59:59Z"
},
"Term":"Current"
}
但是,甚至在调用该操作之前,它就失败并显示错误:
{
"error": {
"code": "0x0",
"message": "CRM do not support direct update of Entity Reference properties, Use Navigation properties instead.",
"innererror": {
"message": "CRM do not support direct update of Entity Reference properties, Use Navigation properties instead.",
"type": "Microsoft.Crm.CrmHttpException",
"stacktrace": " at Microsoft.Crm.Extensibility.OData.TypeConverters.EntityReferenceAttributeTypeConverter.ConvertToCrmTypeInternal(Guid edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmTypeConverterBase`2.ConvertToCrmType(Object edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmEntityTypeConverter.SetStructuralPropertyToXrmEntity(Entity entity, EntityMetadata entityMetadata, String crmAttributeName, IEdmProperty edmProperty, Object propertyValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmEntityTypeConverter.ConvertToCrmTypeInternal(EdmEntityObject edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmTypeConverterBase`2.ConvertToCrmType(Object edmTypeValue)\r\n at Microsoft.Crm.Extensibility.ODataV4.Converters.TypeConverters.OnDemandEdmEntityTypeConverter.ConvertToCrmTypeInternal(EdmEntityObject edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.TypeConverters.EdmTypeConverterBase`2.ConvertToCrmType(Object edmTypeValue)\r\n at Microsoft.Crm.Extensibility.OData.RequestResponseConverter.AddSDKRequestParameterFromEdmOperationParameter(IEdmModel edmModel, IEdmOperation edmOperation, ParameterCollection parameterCollection, KeyValuePair`2 parameter, Tuple`2 messagePair)\r\n at Microsoft.Crm.Extensibility.OData.RequestResponseConverter.GetRequestParamsFromOperationRequest(IEdmModel edmModel, IEdmOperation edmOperation, Dictionary`2 parameters, Dictionary`2 boundParameters, Tuple`2 messagePair, Dictionary`2 offlineData)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.ExecuteOperation(CrmODataExecutionContext context, EdmOperation edmOperation, Dictionary`2 parameters, Dictionary`2 boundParameters)\r\n at Microsoft.Crm.Extensibility.OData.ActionController.ProcessOperationRequest(String operationName, Dictionary`2 operationParameters, EntityReference entityReference, String boundEntityName, String boundEntityType)\r\n at Microsoft.Crm.Extensibility.OData.ActionController.<>c__DisplayClass9_0.<PostUnboundAction>b__0()\r\n at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)\r\n at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
ClubOfficer 不是现有实体,但我希望 Action 将其视为 ClubOfficer 临时实体,以便我可以利用实体属性的 "type safety"。那可能吗?或者我是否必须将 ClubOfficer 作为字符串参数传递,然后对 JSON 字符串进行操作?这个错误是什么意思,我该如何解决?
很遗憾,这是不可能的。您没有将整个实体传递给操作,您只是传递了实体引用,它只是实体的名称及其 ID。所以你无论如何都不能传递额外的值。
执行此操作的正确方法是为每个输入创建额外的输入参数。这样它们将是强类型的。另一种选择是传递一个 JSON 字符串有效负载,您使用自定义 activity.
解析该字符串有效负载希望对您有所帮助!