Have an idea?

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

Different question text conditional on CBC task number

Hi there
I'm trying to use the CBCCURRENTTASK function to have an introductory header on my first CBC task and then slightly different wording for all of the others.  However,  I can't get the code to work.  

This is what I have:-
Begin Unverified Perl

return "text1

return "text2

End Unverified

But it returns "text 2" on all screens.

Any ideas what I'm missing?
asked Mar 29, 2017 by Camila
I'm not an experienced conjoint user but just a comment on your code.

The Perl script looks fine.

The "if" statement is not evaluating to true, hence the reason "text2" is always returned.

Is CBCCURRENTTASK() ever evaluating to "1"? Check some test data.
Thanks - it seems to evaluate to 1 as I'm using this code elsewhere to display the page number as 1.  

As that returns a 1 for the first CBC task I thought it would work in the formula but it seems not

1 Answer

0 votes
Best answer
There are some technical limitations with what can be done with CBCCurrentTask and similar functions in Sawtooth Script.  In situations like this, it may be easier use Sawtooth Script to pass the task number to JavaScript and then do the operations in JS.

<span id="introductoryText"></span>
<input type="hidden" id="cbcTask" value="[% CBCCurrentTask() %]"/>

    var task = Number($('#cbcTask').val());
    var text;
    if (task == 1) {
        text = 'text 1';
    else {
        text = 'text 2';
answered Mar 29, 2017 by Zachary Platinum Sawtooth Software, Inc. (117,475 points)
Thanks for resolving Zachary.