Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error on stringifying object type parameters in buildFunctionParameters(parameters) #45

Closed
Felix-Indoing opened this issue Mar 30, 2019 · 4 comments
Labels

Comments

@Felix-Indoing
Copy link

Felix-Indoing commented Mar 30, 2019

The following code:

buildFunctionParameters({
    Target: {
        'accountid': 'e268122d-114b-e911-a98b-000d3aa00147',
        '@odata.type': 'Microsoft.Dynamics.CRM.account'
    }
})

returns:

(Target=@p1)?@p1=[object Object]

which is not correct.

the expected result would be:

(Target=@p1)?@p1={"accountid":"e268122d-114b-e911-a98b-000d3aa00147","@odata.type":"Microsoft.Dynamics.CRM.account"}

it seems like the code at buildFunctionParameters.js line 23:

urlQuery += "@p" + i + "=" + ((typeof value == "string") ? "'" + value + "'" : value;

could be changed to

urlQuery += "@p" + i + "=" + ((typeof value == "string") ? "'" + value + "'" : JSON.stringify(value));

to solved this issue.

@AleksandrRogov
Copy link
Owner

Hi @Felix-Indoing, what Web API function are you trying to call?

@Felix-Indoing
Copy link
Author

Felix-Indoing commented Mar 30, 2019

Hi, I am using the following code:

    return this.client.executeUnboundFunction('RetrieveSharedPrincipalsAndAccess', {
        Target: {
            'accountid': 'e268122d-114b-e911-a98b-000d3aa00147',
            '@odata.type': 'Microsoft.Dynamics.CRM.account'
        }
    }
    )

@Felix-Indoing
Copy link
Author

Here is the d365 response with the current code:

{
   "code":"0x0",
   "message":"An unexpected 'StartArray' node was found when reading from the JSON reader. A 'StartObject' node was expected.",
   "innererror":{
      "message":"An unexpected 'StartArray' node was found when reading from the JSON reader. A 'StartObject' node was expected.",
      "type":"Microsoft.OData.ODataException",
      "stacktrace":"   at Microsoft.OData.Json.JsonReaderExtensions.ValidateNodeType(IJsonReader jsonReader, JsonNodeType expectedNodeType)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ReadPayloadStartImplementation(ODataPayloadKind payloadKind, PropertyAndAnnotationCollector propertyAndAnnotationCollector, Boolean isReadingNestedPayload, Boolean allowEmptyPayload)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ReadPayloadStart(ODataPayloadKind payloadKind, PropertyAndAnnotationCollector propertyAndAnnotationCollector, Boolean isReadingNestedPayload, Boolean allowEmptyPayload)\r\n   at Microsoft.OData.JsonLight.ODataJsonLightReader.ReadAtStartImplementation()\r\n   at Microsoft.OData.ODataReaderCore.ReadImplementation()\r\n   at Microsoft.OData.ODataReaderCore.InterceptException[T](Func`1 action)\r\n   at System.Web.OData.Formatter.Deserialization.ODataReaderExtensions.ReadResourceOrResourceSet(ODataReader reader)\r\n   at Microsoft.Crm.Extensibility.ODataV4.Routing.CrmODataRouteDataProvider.ConvertToEdmObjectFromODataEntityRef(HttpControllerContext controllerContext, IEdmOperationParameter parameter, Object value, IEdmModel edmModel)\r\n   at Microsoft.Crm.Extensibility.ODataV4.Routing.CrmODataRouteDataProvider.FillUnboundFunctionData(OperationImportSegment unboundFunctionPathSegment, HttpControllerContext controllerContext, IEdmModel edmModel)\r\n   at Microsoft.Crm.Extensibility.ODataV4.Routing.CrmODataRouteDataProvider.ProvideBaseRouteData(ODataPath path, HttpControllerContext controllerContext, Int32 segmentsProcessed, IEdmModel edmModel)\r\n   at Microsoft.Crm.Extensibility.ODataV4.Routing.CrmODataRoutingConvention.SelectActionImplementation(ODataPath odataPath, HttpControllerContext controllerContext, ILookup`2 actionMap)\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 System.Web.OData.Routing.ODataActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n   at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
   },
   "status":400
}

It tells that an unexpected char '[' is occured, where a '{' expected.

@AleksandrRogov
Copy link
Owner

Thanks @Felix-Indoing , that's definitely an incorrect behaviour. I am going to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants