Fetch variable set in jspolicy and print them using assign message policy

i want to do add of two number using JavaScript

i created a proxy as no No target then created a JS policy for adding two number

11063-add.jpg

then i want to print output of c in screen

how can i do that

thanks for any guidance

0 3 228
3 REPLIES 3

i want to print output of c in screen

In which screen? In the Apigee Trace?

You can use the print() function in JS to do that.

var c = parseInt(a) + parseInt(b);
context.setVariable('request.queryparam.added', c);
print('added: ' + c);

It seems to me that if you have a loopback proxy, you don't want to set a query param with the result. Maybe you want to set a response header. like this:

var c = parseInt(a) + parseInt(b);
context.setVariable('response.header.added', c);
print('added: ' + c);<br>

But to make that work, you need to attach the JS policy in the response flow. Not in the request flow.

i want to print in body (response)

Sounds like you want to set the API Proxy response, in which case you can use

context.setVariable('response.content', c)

You also need to ensure your javascript policy is in the response flow otherwise the response will be cleared.