Hi
I am having an issue with XMLHttpRequest in an action script.
Scenario
we run an action script when the workflow state changes, what we want to do is send an email with a ics attachment so that we can add an appointment to a users outlook calendar.
As we can't attach a file to an email we have created a simple web api application. To test that PLM can call out to our REST service we pass a name and email address (hard coded) and then the web api forwards these details on in an email.
var xhr = new XMLHttpRequest();
var value = '{ "EmailAddress": "joe.bloggs@test.com", "Name": "Joe Bloggs" }';
xhr.open("POST", "http://the-url/api/plm", true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Content-Length', value.length);
xhr.send(value);
This actually works however the email and the name are not passed on to my service. My test app works fine.
So I changed the request to
var xhr = new XMLHttpRequest();
var value = EmailAddress=joe.bloggs@test.com&Name=Joe bloggs;
xhr.open("POST", "http://the-url/api/plm", true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('Content-Length', value.length);
xhr.send(value);
This throws a SECURITY_ERR on the first line
My service is enabled for CORS and my test application works fine sending cross origin requests.
Are XMLHttpRequest calls supported in PLM, and if so what am I missing
thanks
Solved! Go to Solution.
Solved by jared.sund. Go to Solution.
sscaife,
Great question, and great inovative approach on extending PLM 360's functionality with web servcies!
There are acouple of quick changes needed here to get this httpRequest to work.
Here's the updated code.
var xhr = new XMLHttpRequest();
var value = '{ "EmailAddress": "joe.bloggs@test.com", "Name": "Joe Bloggs" }';
xhr.open("POST", "http://the-url/api/plm");
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(value);
Let me know if you have any other issues with this, and how it turns out!
-Jared
Hi Jared,
We are going down this route as we'd like to generate an .ics file to add appointments to peoples diaries via an email. I have requested this in the ideastation but for now we are trying to do it via this route.
The code doesn't cause an error in PLM now I've tested it. I just need Steve to test his end
Hi,
Attempting to do something similar but needs basic authentication. Testframework is:
var xhr = new XMLHttpRequest();
xhr.open("GET","https://this.particular.service/board/tasks","myusername","mypassword");
xhr.send();
Result is:
There is an error in the script on line 0, column 0. NETWORK_ERR
Can't figure out why... suggestions?