How can I access the information inside apDetailedResult and apDetailedResult2 in ActivePresenter using JavaScript?

Hello,

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?

Thanks in advance!

These are system variables.

Access to variables - system or otherwise is the same.

prez.variable(“apDetailedResult”);

You probably won’t like the result of this due to the information as a table.
The JavaScript will return the HTML of the table.

You could simply display the results on screen by placing the variable in percentages.

%apDetailedResult2%
This will return the table

If you need to target a specific cell in that table - you could try looking here to see if it gets you further.

1 Like

Hello Greg,

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?

I do not have anything else.

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.