Difference between revisions of "QuestionCondition class"

From Catglobe Wiki
Jump to: navigation, search
 
Line 23: Line 23:
 
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Inherited=object|Description=<nowiki>Get information about this class.</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Inherited=object|Description=<nowiki>Get information about this class.</nowiki>}}
 
}}
 
}}
 +
 +
=== <span style="color:#DF8621">'''Examples'''</span> ===
 +
<source lang="javascript">
 +
//new condition for a question
 +
//noted that, system not validate wrong condition info (label/expression...)
 +
Questionnaire qnaire = new Questionnaire (17148177);
 +
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
 +
QuestionTemplate q = qt.GetQuestion("Q1");
 +
QuestionCondition c = new QuestionCondition (Condition_Type_GotoIf, q);
 +
c.Label = "EndOutside";
 +
c.Expression = "Q1 == [4]" ;
 +
qt.Save(true);
 +
</source>
 +
<source lang="javascript">
 +
//edit existing condition
 +
Questionnaire qnaire = new Questionnaire (17148177);
 +
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
 +
QuestionTemplate q = qt.GetQuestion("Q1");
 +
print(q.Conditions);//{QuestionCondition, ...}
 +
for(i for 0; q.Conditions.Count){
 +
QuestionCondition c = q.Conditions[i];
 +
if (c.ConditionTypeAsString == "GotoIf"){
 +
c.Label = "EndOutside";
 +
c.Expression= "Q1== [3]";
 +
}
 +
}
 +
qt.Save(true);
 +
</source>

Latest revision as of 08:32, 11 May 2022

QuestionCondition



The question condition.

Parent class

Inherits from object

Constructors

  • (int id "Question condition id") - Fetch exists question condition
  • (ConditionType constant type "Condition type, use constant Condition_Type_xxx", QuestionTemplate question "Question contains this condition") - Create new condition and add it to question template

Methods

  • (From object) string ToString() - The string representation of the object.

Properties

  • ConditionType constant ConditionType { get; set; } - Get/Set ConditionType of the question condition, use constant Condition_Type_xxx
  • string ConditionTypeAsString { get; } - Get ConditionType as string of the question condition
  • string Expression { get; set; } - Get/Set Expression of the question condition
  • int Id { get; } - Get Id of the question condition
  • string Label { get; set; } - Get/Set Label of the question condition
  • string ObjectTypeName { get; } - The name of the type of object.
  • int QuestionID { get; } - Get QuestionID of the question condition
  • string Range { get; set; } - Get/Set Range of the question condition
  • Dictionary Replacements { get; set; } - Get/Set Replacements of the question condition (only valid for ReplaceIf). Its value is a Dictionary with key is label to replace and value is LocalizedString
  • (From object) TypeInformation TypeInformation { get; } - Get information about this class.


Examples

//new condition for a question
//noted that, system not validate wrong condition info (label/expression...)
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionTemplate q = qt.GetQuestion("Q1");
QuestionCondition c = new QuestionCondition (Condition_Type_GotoIf, q);
c.Label = "EndOutside";
c.Expression = "Q1 == [4]" ;
qt.Save(true);
//edit existing condition 
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionTemplate q = qt.GetQuestion("Q1");
print(q.Conditions);//{QuestionCondition, ...}
for(i for 0; q.Conditions.Count){
	QuestionCondition c = q.Conditions[i];
	if (c.ConditionTypeAsString == "GotoIf"){
		c.Label = "EndOutside";
		c.Expression= "Q1== [3]";	
	}	
}
qt.Save(true);