Unable to evaluate a Script-runner JSON response in Java

Anders Borup January 31, 2018

Been trying for some time now to get the response from my J-SON script to be correctly evaluated so that I in the macro can choose depending on the response to either do stuff on the elements

Have tried several solutions

attempts.jpg

 1 and 3 are when evaluated in the Chrome browser actually ending up with the correct result. But the IF statement keeps going for false...... HELP (not because of missing { or }

Thank you for any help you can give

scripts.jpg

2 answers

1 accepted

0 votes
Answer accepted
Anders Borup January 31, 2018

Problem solved, JSON are running in async mode (sync mode are deprecated)

So to handle the response in a user macro, you need a response function to handled the response like shown below

xmlHttp.onreadystatechange = function (e) {
if (xmlHttp.readyState === 4) {
if (xmlHttp.status === 200) {
if (xmlHttp.response === '{"PageRead":true}') {
document.getElementById('AwareRead').style.display = 'none';
}
else {
document.getElementById('AwareNotRead').style.display = 'none';
}
} else {
console.error(xmlHttp.statusText);
}
}
};
0 votes
Anders Borup January 31, 2018

Just had a competent debugger looking at the code and doing some debugging and it appear that xmlHttp.response hasn't been load with any value when the IF evaluation is executed .... 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events