// returns a true if the word 'agree' is not found in the text strong function ContainsAgree(label) { return false;//label.indexOf('agree') == -1; } // checks if the question name contains 'agree' function NameContainsAgree(question) { var name = question.name.toLowerCase(); // The question name converted lower case return ContainsAgree(name); // } // checks to see if the value labels contain 'agree' function ValueLabelsContainAgree(question) { for (var value_i = question.uniqueValues.length - 1; value_i >= 0; value_i --) {//loops through the value labels var label = question.valueAttributes.getLabel(q.uniqueValues[value_i]).toLowerCase(); if (label.indexOf('agree') != -1) // looks for a label containing agree return true; } return false; } // checks to see if a label represents a don't know function IsDontKnow(label) { var possible = ["dk","d.k.","don't know","dont know","unsure","un-sure","not sure","do not know","no idea"]; for (var i in possible) if((label).toLowerCase().indexOf(possible[i]) != -1) return true; return false; } // Creating a new group for the reports. var TopTwoBoxesTables = project.report.appendGroup(); TopTwoBoxesTables.name = ("Top 2 Box Tables"); var created_questions = [];// an array to store created_questions var source_questions = [];// an array to store created_questions var log_report = ""; //looping through all the questions in a project for (var data_i in project.dataFiles){ //looping through all the data files var data_file = project.dataFiles[data_i] for (var q_i in data_file.questions) {//looping through all the questions in the file var q = data_file.questions[q_i]; if ((q.questionType == "Pick One - Multi" || q.questionType == "Pick One") && !q.isHidden // ignoring hidden questions && q.name.indexOf('AGREE (TOP 2 BOXES)') == -1 // ensuring we do not analyze one of the new question && (NameContainsAgree(q) || ValueLabelsContainAgree(q))) { // seems to measure agreement var n_uniques = q.uniqueValues.length; if (n_uniques >= 4 && n_uniques <= 7) { var new_q = data_file.getQuestionByName(q.name).duplicate(q.name + " AGREE (TOP 2 BOXES)"); //creating the new question created_questions.push(new_q); source_questions.push(q); new_q.questionType = "Pick Any"; //setting the type for (var value_i = 0; value_i < new_q.uniqueValues.length; value_i ++) { var source_value = new_q.uniqueValues[value_i]; var label = q.valueAttributes.getLabel(source_value); if (IsDontKnow(label)) log_report += q.name + " seems to contain Don't Knows and the new question (" + new_q.name + ") should be checked.\r\n"; new_q.valueAttributes.setCountThisValue(source_value, value_i >= n_uniques - 2) } } } } for (var q_i = 0; q_i < created_questions.length; q_i++) {//looping through all the questions in the file var q = created_questions[q_i]; var t = TopTwoBoxesTables.appendTable();// add tables showing the top two boxes t.primary = q; } } log("All done");