It doesn’t. As said - I’m in a script tag. When I do the above - it sets it to the value of jsonObject as a string - which is then represented at jsonObject - instead of the content of the jsonObject tag in the script.
Instead of the content of the jsonObject variable which is:
here is my code:
<script>
$(document).ready(function(){
$("#fileUploader").change(function(evt){
var selectedFile = evt.target.files[0];
var reader = new FileReader();
reader.onload = function(event) {
var data = event.target.result;
var workbook = XLSX.read(data, {
type: 'binary'
});
workbook.SheetNames.forEach(function(sheetName) {
var XL_row_object = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
var json_object = JSON.stringify(XL_row_object);
document.getElementById("jsonObject").innerHTML = json_object;
${pm.environment.set('trades', 'json_Object')};
})
};
reader.onerror = function(event) {
console.error("File could not be read! Code " + event.target.error.code);
};
reader.readAsBinaryString(selectedFile);
});
});
</script>
Once in a script - I’m flummuxed as to how to send script variables back to postman. It is easy to send postman variables into the script - but none of the methods I’ve tried seem to work.
As you see - the var = json_object has been initialized with the jsonObject. I now want to write eiher jsonObject - or the content of the var to an environment variable.