Difference between revisions of "QuestionGroupLeaf class"

From Catglobe Wiki
Jump to: navigation, search
Line 25: Line 25:
  
 
=== <span style="color:#DF8621">'''Examples'''</span> ===
 
=== <span style="color:#DF8621">'''Examples'''</span> ===
<span style="color:#DF8621"> QuestionGroupLeaf is returned when calling [[QuestionGroupRoot_class]]</span>
 
 
<source lang="javascript">
 
<source lang="javascript">
number qnaireRId = 15644704;
+
//Find a group leaf by its question
QuestionGroupRoot root = Questionnaire_getQuestionGroups(qnaireRId);
+
number qnaireRId = 17148177;
 +
//QuestionGroupRoot root = Questionnaire_getQuestionGroups(qnaireRId);
 +
QuestionGroupRoot root = new QuestionnaireTemplate(new Questionnaire(17148177).TemplateId).Groups;
 
QuestionGroupLeaf leaf = root.FindByQuestion("Q1");
 
QuestionGroupLeaf leaf = root.FindByQuestion("Q1");
print(leaf.GroupName);//G2
+
print(leaf.GroupName);//G1
 +
</source>
 +
<source lang="javascript">
 +
//create new group leaf
 +
Questionnaire qnaire = new Questionnaire (17148177);
 +
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
 +
QuestionGroupLeaf g1 = new QuestionGroupLeaf ("G1", qt);
 +
g1.SetQuestions({"Q1", "Q2"});//Questions must in order
 +
//add the group leaf to group root
 +
array groupRoot = qt.Groups.GetChildGroups();
 +
groupRoot.Add(g1);
 +
qt.Groups.SetChildGroups(groupRoot);
 +
qt.Save(true);
 +
</source>
 +
<source lang="javascript">
 +
//add more questions for an existing group leaf
 +
Questionnaire qnaire = new Questionnaire (17148177);
 +
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
 +
QuestionGroupLeaf g1 = qt.Groups.FindByName("G1");
 +
// add more question to questions array
 +
array questions = g1.GetQuestions();
 +
questions.Add("Q3");
 +
g1.SetQuestions(questions);
 +
qt.Save(true);
 
</source>
 
</source>

Revision as of 09:58, 11 May 2022

QuestionGroupLeaf


Question group leaf.

Parent class

Inherits from QuestionGroupTree

Constructors

Methods

  • Array of String GetQuestions() - Return label of questions in group
  • Empty SetQuestions(Array of String labels "Question labels") - Set questions in group by their label
  • (From object) string ToString() - The string representation of the object.

Properties


Examples

//Find a group leaf by its question
number qnaireRId = 17148177;
//QuestionGroupRoot root = Questionnaire_getQuestionGroups(qnaireRId);
QuestionGroupRoot root = new QuestionnaireTemplate(new Questionnaire(17148177).TemplateId).Groups;
QuestionGroupLeaf leaf = root.FindByQuestion("Q1");
print(leaf.GroupName);//G1
//create new group leaf
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionGroupLeaf g1 = new QuestionGroupLeaf ("G1", qt);
g1.SetQuestions({"Q1", "Q2"});//Questions must in order
//add the group leaf to group root
array groupRoot = qt.Groups.GetChildGroups();
groupRoot.Add(g1);
qt.Groups.SetChildGroups(groupRoot);
qt.Save(true);
//add more questions for an existing group leaf
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionGroupLeaf g1 = qt.Groups.FindByName("G1");
// add more question to questions array
array questions = g1.GetQuestions();
questions.Add("Q3");
g1.SetQuestions(questions);
qt.Save(true);