Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Functionality based on specific pairs (ACA)


For an ACA survey, can functionality be built-in which displays unique content only when very specific pairings are put together?

For example, when Attr1/Lvl1 is paried with Attr3/Lvl3, there is extra text that shows up to say something to the effect of "this specific pairing will cost $x".

I imagine it is theoretically possible, given that ACA codifies each level as a numeric value, and uses a negative sign to denote left-side vs. right-side.

Thoughts/insights/comments welcome. Thanks!
asked Jul 28, 2016 by WTW_cal Bronze (1,595 points)
I don't believe ACAs have any sort of built-in conditional relationships, but I'd be happy to help create this effect with JavaScript.  Where would you like the conditional text to appear?  Should I just add it as a new row to the ACA Pair table?
Thanks for any help you can provide. A new row in the table is probably the best spot for it.

1 Answer

0 votes
Alright, here's the code that can be put in the ACA Pair footer:

    var cond1 = setAcaConditionalText(1);
    var cond2 = setAcaConditionalText(2);
    if (cond1 !== '' || cond2 !== '') {
        // Stretch middle column
        var rowspan = parseInt($('.acapair .acapair_table > tbody > tr:first-child > td:nth-child(2)').attr('rowspan'));
        $('.acapair .acapair_table > tbody > tr:first-child > td:nth-child(2)').attr('rowspan', rowspan + 1);
        // Determine alternating colors
        var leftColor = $('.left_concept').first().hasClass('alt_color1') ? 'alt_color1' : 'alt_color2';
        var rightColor = $('.right_concept').first().hasClass('alt_color1') ? 'alt_color1' : 'alt_color2';
        // Append new row
        $('.acapair .acapair_table > tbody').append(`
                <td class="level_text_cell left_concept ` + leftColor + `" width="45%">
                    <div class="level_text">
                        ` + cond1 + `
                <td class="level_text_cell right_concept ` + rightColor + `" width="45%">
                    <div class="level_text">
                        ` + cond2 + `

function setAcaConditionalText(pair) {
    var attr1 = getAcaLevel(pair, 1);
    var attr2 = getAcaLevel(pair, 2);
    if (attr1 == 'att 1 - lev 1' && attr2 == 'att 2 - lev 1') {
        return 'text 1';
    if (attr1 == 'att 1 - lev 2' && attr2 == 'att 2 - lev 2') {
        return 'text 2';
    if (attr1 == 'att 1 - lev 3' && attr2 == 'att 2 - lev 3') {
        return 'text 3';
    return '';

function getAcaLevel(pair, attr) {
    var td = (pair == 2 && attr == 1) ? 3 : pair;
    return $('.acapair .acapair_table > tbody > tr:nth-child(' + attr + ') > td:nth-child(' + td + ') .level_text').text().trim();

Currently, this code reads the first and second attributes, then sets the conditional text to "text 1," "text 2", or "text 3" under certain circumstances.  You can adjust this to meet your needs by modifying the region from line 34 to line 45.
answered Jul 28, 2016 by Zachary Platinum Sawtooth Software, Inc. (182,000 points)
Thanks Zachary. I am not sure I follow the logic of the code.  

Do lines 34/35 care if the pairing is on the left-hand side or the right? And lines 37, 40, and 43 are intended to look for the exact text of the level (formatting and all)?

So far, I am not having much luck with it. Thanks.
Sorry for the confusion.  I try to keep my code minimal usually, but this particular problem ended up requiring a decent amount of code to look good.

The code from line 33 to line 48 is run twice for each Pair question: first for the left side, then for the right side.  So the first time lines 34-35 run, it produces the levels on the left side; the second time lines 34-35 run, it produces the levels on the right side.  This way, the conditional pairing in lines 37-45 automatically applies to both sides.

The code looks for the non-HTML text of the level.  So if a label was something like "<b>Brand A</b>", you would want to just use "Brand A."  If your levels are images or something else with more code, I'd need to make adjustments of the code to make it work.

Is it possible for you to send me a copy of your study to work on, with any secure or irrelevant content stripped out?  If I have the exact levels and such, I'm sure I could get it working.