I’m working with ActivePresenter and trying to access the data inside apDetailedResult and apDetailedResult2 using JavaScript.
Can someone please guide me on how to retrieve or interact with these objects in the script?
Thank you for your detailed explanation and guidance!
I reviewed the link you shared and, I was able to extract the content I needed with a simple function:
Perhaps there is also a way to access the data directly without parsing the HTML, but I couldn’t find it. So this approach was a bit more work, but it does the job.
function parseApDetailedResult(varName) {
var html = prez.variable(varName);
if (!html) return [];
var tempDiv = document.createElement('div');
tempDiv.innerHTML = html;
var table = tempDiv.querySelector('table');
if (!table) return [];
var headers = [];
table.querySelectorAll('thead th').forEach(th => {
headers.push(th.innerText.trim());
});
var rows = [];
table.querySelectorAll('tbody tr').forEach(tr => {
var cells = tr.querySelectorAll('td');
var rowData = {};
cells.forEach((td, index) => {
var header = headers[index] || `col${index}`;
rowData[header] = td.innerText.trim();
});
rows.push(rowData);
});
return rows;
}
function getLearnerResponses(varName) {
var data = parseApDetailedResult(varName);
return data.map(row => row["Learner Response"] || "");
}
var responses = getLearnerResponses("apDetailedResult2");
console.log(responses);
What do you think? Do you know if there is a more straightforward way to access this data?
My solution is to take that data to an array so it can be more easily referenced.
Without actually running your code - it appears that is what you’re doing as well.