How do I create a Request object in JavaScript and add it to the context for later use?

Not applicable

I want to create and populate a request object in JavaScript that can be used downstream in a Service Callout. When I try to create a request object in code with new Request(), then save it using context.setVariable(), it cannot be used in a Service Callout. I get this error:

{"fault":{"detail":{"errorcode":"steps.servicecallout.RequestVariableNotMessageType"},"faultstring":"ServiceCallout[Service-Callout]: request variable manuallyCreated value is not of type Message"}}

I found that I can do context.setVariable('newMessage', context.getVariable('message')), and that works downstream. Obviously, new Request() is not the same as the request flow variable.

Is there a way to construct a new Message within JavaScript?

Solved Solved
1 2 1,719
1 ACCEPTED SOLUTION

Not applicable

Hi Lee Grey

I tried to setup variable in js and set it in the request in callout policy.

I attached some screenshots, hope they are helpful for you.

4393-screen-shot-2017-02-28-at-111811-pm.png

4394-screen-shot-2017-02-28-at-111820-pm.png

4395-screen-shot-2017-02-28-at-111830-pm.png

View solution in original post

2 REPLIES 2

Hey Lee, can you show your servicecallout configuration?

A possible workaround is to just create the body of the request is the JS callout, and specify just that for the payload in the servicecallout, while everything else is specified explicitly with elements in the servicecallout.

If you don't like that idea, then here's another workaround possibility: you could use AssignMessage to create a new message (createNew="true") prior to the JS callout, and then the JS callout would retrieve and modify that message.

But I agree, it would be nice to be able to create a new Message in JS directly.

Not applicable

Hi Lee Grey

I tried to setup variable in js and set it in the request in callout policy.

I attached some screenshots, hope they are helpful for you.

4393-screen-shot-2017-02-28-at-111811-pm.png

4394-screen-shot-2017-02-28-at-111820-pm.png

4395-screen-shot-2017-02-28-at-111830-pm.png