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


if(CBCCURRENTTASK()==1)
{
return "text1
"
}

else
{
return "text2
"
}

End Unverified
%]


But it returns "text 2" on all screens.

Any ideas what I'm missing?
asked Mar 29 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.  
[%CBCCurrentTask()%]

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() %]"/>

<script>
$(document).ready(function(){
    var task = Number($('#cbcTask').val());
    var text;
    if (task == 1) {
        text = 'text 1';
    }
    else {
        text = 'text 2';
    }
    $('#introductoryText').text(text);
})
</script>
answered Mar 29 by Zachary Platinum Sawtooth Software, Inc. (63,675 points)
Thanks for resolving Zachary.
...