cancel
Showing results for 
Search instead for 
Did you mean: 

Calling rest service using script task in Activiti rest

harshsinghx
Champ in-the-making
Champ in-the-making
Hi

I want to hit a rest web service using javascript code in script task .
I am using Activiti rest but getting error XmlHttpRequest not found error.
Can anyone here help.
3 REPLIES 3

trademak
Star Contributor
Star Contributor
Hi,

Difficult to say much without more details. Probably you are using not the correct url.

Best regards,

rpachouli
Champ in-the-making
Champ in-the-making
<scriptTask id="scripttask1" name="Script Task" scriptFormat="javascript" activiti:autoStoreVariables="false">
<script>
<![CDATA[
importPackage(java.io, java.net);
var url = new URL('http://***************************************/employee/service/v1.0/search/getEmployee?id=105');

var urlStream = url.openStream();
  var reader = new BufferedReader(new InputStreamReader(urlStream, "latin1"));

  var html = "";
  var line;
  while (line = reader.readLine()) {
   if (line == null) break;
   html += line;
  }
  var arr = JSON.parse(html);
  execution.setVariable("myVar", arr.id);
  print(arr.name);
]]>
</script>
</scriptTask>

rpachouli
Champ in-the-making
Champ in-the-making
<scriptTask id="scripttask1" name="Script Task" scriptFormat="javascript" activiti:autoStoreVariables="false">
<script>
<![CDATA[
importPackage(java.io, java.net);
var url = new URL('http://******/employee/service/v1.0/search/getEmployee?id=105');

var urlStream = url.openStream();
  var reader = new BufferedReader(new InputStreamReader(urlStream, "latin1"));

  var html = "";
  var line;
  while (line = reader.readLine()) {
   if (line == null) break;
   html += line;
  }
  var arr = JSON.parse(html);
  execution.setVariable("myVar", arr.id);
  print(arr.name);
]]>