1

I am working on the platform confirmit, which creates online surveys. This is a script node that results in the runtime error "object required", I would be grateful if you could help me fix it.. It is supposed to check whether certain codes hold 1 or 2 in the questions q2b and q3a (questions are referenced with the function f() - f(question id)[code]) - the '//skip ?' part. Then it recodes a maximum of four of the codes into another question (h_q4) for further use.

var flag1 : boolean = false;
var flag2 : boolean = false;

//null
for(var i: int=0; i <9; i++)
{
    var code = i+1;
    f("h_q4")[code].set(null);
}
f("h_q4")['95'].set(null);

//skip ?
for(var k: int=1; k <16; k+=2)
{
    var code = k;
    if(f("q2b")[code].none("1", "2"))
        flag1;
    else
    {
        flag1 = 0;
        break;
    }
}

if(f("q3a")['1'].none("1", "2"))
flag2;

if(flag1 && flag2)
f("h_q4")['95'].set("1");
//recode 
else 
{
    var fromForm = f("q2b"); 
    var toForm = f("h_q4"); 
    const numberOfItems : int = 4; 
    var available = new Set(); 
    if(!flag1)
    {
        for( i = 1; i < 16; i+=2)
        {
            var code = i;

            if(f("q2b")[i].any("1", "2"))
            available.add(i); 
        }
    }
    if(!flag2)
    {
        available.add("9");
    }
    var selected = new Set(); 
    if(available.size() <= numberOfItems) 
    { 
        selected = available; 
    } 
    else 
    { 
        while(selected.size() < numberOfItems) 
        {
            var codes = available.members();
            var randomNumber : float = Math.random()*codes.length;
            var randomIndex : int = Math.floor(randomNumber);
            var selectedCode = codes[randomIndex];
            available.remove(selectedCode);
            selected.add(selectedCode); 
        }
    } 
    var codes = fromForm.domainValues();
    for(var i = 0;i<codes.length;i++) 
    {
        var code = codes[i]; 
        if(selected.inc(code)) 
        { 
            toForm[code].set("1"); 
        }
        else
        { 
            toForm[code].set("0"); 
        } 
    }
}

the first part of the code (//null) empties the 'recepient' question to ease testing
.set(), .get(), .any(), .none() are all valid

KGS
  • 635
  • 4
  • 19
  • `var flag1 : boolean = false;` looks suspicious, what does it do? – Teemu Jul 20 '12 at 07:14
  • i fixed it... in the last loop i was refering to non-existant codes as i forgot the two questions have different domain values for( i = 1; i < 16; i+=2) { var code = i; if(f("q2b")[i].any("1", "2")) available.add(i); } i also had to add a counter here beacuse of the same issue and the flags are used to determine whether the previous question codes meet the conditions required for them to be displayed – KGS Jul 20 '12 at 10:44

0 Answers0