1

I'm currently trying to send data from a Polarion work item to a Java servlet. I have a post-save trigger which upon saving my work activates my javascript. This script is supposed to check the work item fields for data, validate it and transmit it to my servlet via a POST request.

To enable this post save trigger in Polarion I'm using the following plugin. https://extensions.polarion.com/extensions/134-fmc-work-item-save I can already get the data from all the work item fields. The only thing I am unable to do is create a XMLHttpRequest.

var xhr =  new XMLHttpRequest();

xhr.open("POST", "/postservlet", true);

xhr.setRequestHeader("Content-Type", "application/json");

xhr.setRequestHeader("Accept", "application/json"); 

xhr.send(JSON.stringify({value: "test"}));

returns:

TypeError: this.XMLHttpRequest is not a function

I am by no means an experienced web developer but this means the javascript can't access the browser window global methods since I am using a plugin to load the javascript and it's not being added to the HTML page directly.

Including something like jquery from a CDN is also currently not possible.

I am looking for a way to allow this script to use the XMLHttpRequest or for some other way to enable post requests in Polarion. Either via a different plugin or by editing the source code (if that's even possible).

OliverSM
  • 11
  • 4

1 Answers1

0

The XMLHttpRequest-object is not part of the Javascript Context of the JavaSavehook. So you cannot use it.

The Javascript Interpreter"Rhino" does not have an XMLHttpRequest object because it is just wrapping the Java Network classes.

XMLHttpRequest in Rhino? (but I doubt the solution helps you..)

Peter Parker
  • 29,093
  • 5
  • 52
  • 80