JavaScript Runtime Error

Not applicable

Hi, Currently i am getting below response. I want to map json response to javascript with nested loop and also added javascript policy but getting javascript error. please anyone guide me.

	{"fault":{"faultstring":"Execution of MappingResources failed with error: Javascript runtime error: \"RangeError: Inappropriate array length. (ConstructRespnces-1.js:113)\"","detail":{"errorcode":"steps.javascript.ScriptExecutionFailed"}}}

The full proxy is attached.

EDIT: My javascript code working fine as simply way but i wanted this code iterate through looping, nested arrays loop but i try to implement with array then getting javascript error. please try to resolve this issue.Thanks.

4920-getdata-rev1-2017-05-24.zip

0 2 881
2 REPLIES 2

hadleena
Participant III

@tanhooiling ,

Could you please be more clear on what you would like to do with the json response in the javascript policy?

If you can, please share your code here, for anyone to point out if anything is missing in the code. Thanks

It seems the line in your JS that is causing the error is 113.

I believe this is the line:

    context.proxyResponse.content = JSON.stringify(responseVar);

The problem, maybe, is that the context.proxyResponse does not exist. Not sure, because the actual error message is "RangeError: Inappropriate array length". But I'm just guessing here.

IF that is so, then...

I believe that property on the context object does not exist until the target flow completes. SInce your policy is attached to the target response flow, that causes the error.

You can correct this in one of two ways:

  • move the policy
  • change the JS code

For the first, if you move the policy to the response flow in the PROXY endpoint, then the symbol will be defined, and the error should go away.

For the latter, if you change the JS code to be like this:

context.response.content = JSON.stringify(responseVar);

..then the error should go away.

context.response is a shorthand that refers to the response object, whether it is the proxy response or the target response, depending on where in the logic flow the code executes. Since your code is executing (currently) in the target response flow, context.response will actually refer to context.targetResponse. Your original code refers to context.proxyResponse. You could also modify the code to explicitly refer to context.targetResponse.

If you don't need to retain the targetResponse as distinct form proxyResponse, then I would suggest using the shorthand "wildcard" property name of context.response.

If this is not the problem, then....

Maybe you could attach an example response payload that you get from Allianz, and we can try diagnosing it directly. You will need to remove any PII or PHI before posting that example.

good luck!