Have an idea?

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

Display levels of merged attributes with comma separator

Hi,

I have merged rows in ACBC. I want merged attributes levels are to be displayed with comma instead of being listed by one by one. Is it possible?

Regular output
--------------------

                                       | Level 1
Merged attributes  | Level 2
                                       | Level 3


Require output
---------------------

Merged attributes | Level 1, Level 2 and Level 3
asked Oct 5, 2017 by Abdul Bronze (2,630 points)

1 Answer

+1 vote
 
Best answer
Set your merged rows to have no level format, then add this code to your screener and choice tasks:

<script>
$(document).ready(function(){
    $('.acbc_merged_level:first-child').each(function(){
        var first = $(this);
        var middle = $(first).siblings('.acbc_merged_level:not(:last-child)');
        var last = $(first).siblings('.acbc_merged_level:last-child');
        $(middle).each(function(){
            var sibling = $(this);
            $(first).text($(first).text() + ', ' + $(sibling).text());
            $(sibling).remove();
        });
        $(first).text($(first).text() + ' and ' + $(last).text());
        $(last).remove();
    });
})
</script>
answered Oct 5, 2017 by Zachary Platinum Sawtooth Software, Inc. (147,925 points)
selected Oct 5, 2017 by Abdul
Thanks Zachary for your help.
It works great however not for constructed list merged attributes which have only one level. Getting output as
'First Level and'
' and Last Level'
Need to remove the word 'and' if constructed list merged attribute has only one level. It works great if the merged attribute has two or more levels.
<script>
$(document).ready(function(){
    $('.acbc_merged_level:first-child').each(function(){
        var first = $(this);
        var middle = $(first).siblings('.acbc_merged_level:not(:last-child)');
        var last = $(first).siblings('.acbc_merged_level:last-child');
        $(middle).each(function(){
            var sibling = $(this);
            $(first).text($(first).text() + ', ' + $(sibling).text());
            $(sibling).remove();
        });
        if ($(last).length) {
            $(first).text($(first).text() + ' and ' + $(last).text());
            $(last).remove();
        }
    });
})
</script>
It works great. Thanks Zachary.
...