Problem with Javascript variable - HTTP-Connector Response usage

how to retrieve a value from javascript in camunda output parameter ?

I am calling a REST service using http-connector and am getting the response as JSON object.
I want to parse the response in javascript and get the value from it.
I want to get that o/p value in the next activiti, so how can i keep that in process again in javascript ?
my javascript code looks like below

<camunda:outputParameter name=“approverId”>
<camunda:script scriptFormat=“Javascript”></camunda:script>
</camunda:outputParameter>

@sunkiranforu when using the Http-connector set your output variable with a inline JS where you have S(response) . This uses Camunda’s “spin framework” which will parse the JSON string into a JSON object.

If you just want to keep the userID as your output variable do something like
S(response).prop("userid");

If you are accessing the response in other locations (based on your code sample), it would look something like this:

var response = execution.getVariable("WsResponse"); 
var approverId = response.prop("userid");

Or just

var approverId = execution.getVariable("WsResponse").prop("userid");
1 Like

Thank you , I have tried the it is working with your changes and it is working with the below changes to my code also in Javascript.

var response = connector.getVariable(“response”);
obj = JSON.parse(response);
obj.userid;

the obj.userid value is getting set in the outputParameter directly and am able to access by execution.getVariable(“outputParameterName”);

otherwise , we can set the variable like below.

execution.setVaraible(“variableName”);

@sunkiranforu take a look at: Any Benefits of using Spin over Javascript Objects when using javascript Scripting for information on Pros vs Cons of using the Nashorn vs Spin JSON.

(Basically when you are doing JSON.parse() you are using Nashorn) - see the link above.

Hi…I am also trying to do the same thing…
Hitting the Url and then getting a JSON Response…Now I want to Use Values from that JSON response and display in the form.

But in the Tasklist I am getting below error:
**An error happend while submitting the task form : **
Cannot submit task form e974bf48-92bf-11e6-99c6-d43d7ec7ada1: Unable to evaluate script: sun.org.mozilla.javascript.internal.EcmaError: SyntaxError: Empty JSON string (#1) in at line number 1

Consider Below as the JSON Response:
{
“recordSetTotal”: “1”,
“resourceName”: “productview”,
“recordSetComplete”: “true”,
“recordSetStartNumber”: “0”,
}
Need Help…

Thanks,
Tushar

1 Like

HI Tushar,
I am also trying similar one ,get the response and display in the form .if you have completed could you please share me the code.
thanks,
Bala

You need to access the value of json property

https://docs.camunda.org/manual/7.8/reference/spin/json/01-reading-json/#reading-json-properties

Can also take a look at: https://medium.com/@stephenrussett/deploying-external-scripts-with-camunda-rest-api-e06bd90a2931

HI Stephen,
I need some help .
1.crete Embedded HTML and inserted into USER task form
2.Read the USER’s input and call the REST service (POST).
3.In another form I want to display the REST response (JSON).
Please let me know how to do that,I didn’t see anywhere this implementation .

Thaks,
Bala

Look at

And