Difference between revisions of "QuestionCondition class"
(Created page with "{{CGscriptClass_Template |Name=<nowiki>QuestionCondition</nowiki> |Description=<nowiki>The question condition.</nowiki> |InheritsFrom=object|Methods= {{CGscriptMethods_Templat...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 2: | Line 2: | ||
|Name=<nowiki>QuestionCondition</nowiki> | |Name=<nowiki>QuestionCondition</nowiki> | ||
|Description=<nowiki>The question condition.</nowiki> | |Description=<nowiki>The question condition.</nowiki> | ||
− | |InheritsFrom=object|Methods= | + | |InheritsFrom=object|Constructors= |
+ | {{CGscriptConstructors_Template|Parameters= | ||
+ | {{CGscriptParameters_Template|Type=int|Name=<nowiki>id</nowiki>|Description=<nowiki>Question condition id</nowiki>}} | ||
+ | |Description=<nowiki>Fetch exists question condition</nowiki>}} | ||
+ | {{CGscriptConstructors_Template|Parameters= | ||
+ | {{CGscriptParameters_Template|Type=ConditionType constant|Name=<nowiki>type</nowiki>|Description=<nowiki>Condition type, use constant Condition_Type_xxx</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=QuestionTemplate|Name=<nowiki>question</nowiki>|Description=<nowiki>Question contains this condition</nowiki>}} | ||
+ | |Description=<nowiki>Create new condition and add it to question template</nowiki>}} | ||
+ | |Methods= | ||
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Inherited=object|Description=<nowiki>The string representation of the object.</nowiki>}} | {{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Inherited=object|Description=<nowiki>The string representation of the object.</nowiki>}} | ||
|Properties= | |Properties= | ||
− | {{CGscriptProperties_Template|ReturnType= | + | {{CGscriptProperties_Template|ReturnType=ConditionType constant|Name=<nowiki>ConditionType</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get/Set ConditionType of the question condition, use constant Condition_Type_xxx</nowiki>}} |
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ConditionTypeAsString</nowiki>|HasGetter=1|Description=<nowiki>Get ConditionType as string of the question condition</nowiki>}} | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ConditionTypeAsString</nowiki>|HasGetter=1|Description=<nowiki>Get ConditionType as string of the question condition</nowiki>}} | ||
− | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>Expression</nowiki>|HasGetter=1|Description=<nowiki>Get Expression of the question condition</nowiki>}} | + | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>Expression</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get/Set Expression of the question condition</nowiki>}} |
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Id</nowiki>|HasGetter=1|Description=<nowiki>Get Id of the question condition</nowiki>}} | {{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>Id</nowiki>|HasGetter=1|Description=<nowiki>Get Id of the question condition</nowiki>}} | ||
− | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>Label</nowiki>|HasGetter=1|Description=<nowiki>Get Label of the question condition</nowiki>}} | + | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>Label</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get/Set Label of the question condition</nowiki>}} |
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}} | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}} | ||
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>QuestionID</nowiki>|HasGetter=1|Description=<nowiki>Get QuestionID of the question condition</nowiki>}} | {{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>QuestionID</nowiki>|HasGetter=1|Description=<nowiki>Get QuestionID of the question condition</nowiki>}} | ||
− | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>Range</nowiki>|HasGetter=1|Description=<nowiki>Get Range of the question condition</nowiki>}} | + | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>Range</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get/Set Range of the question condition</nowiki>}} |
− | {{CGscriptProperties_Template|ReturnType=Dictionary|Name=<nowiki>Replacements</nowiki>|HasGetter=1|Description=<nowiki>Get Replacements of the question condition | + | {{CGscriptProperties_Template|ReturnType=Dictionary|Name=<nowiki>Replacements</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>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</nowiki>}} |
{{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);