Difference between revisions of "QuestionnaireTemplate class"
(Created page with "{{CGscriptClass_Template |Name=<nowiki>QuestionnaireTemplate</nowiki> |Description=<nowiki>The questionnaire template.</nowiki> |InheritsFrom=object|Constructors= {{CGscriptCo...") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 46: | Line 46: | ||
{{CGscriptMethods_Template|ReturnType=Dictionary|Name=<nowiki>QuestionnaireTemplate_getActiveLanguages</nowiki>|Description=<nowiki>Return a Dictionary of all languages supported in system. The dictionary item has key is iso code and value is object {isocode: string, name: string, viewerSupported: bool}</nowiki>}} | {{CGscriptMethods_Template|ReturnType=Dictionary|Name=<nowiki>QuestionnaireTemplate_getActiveLanguages</nowiki>|Description=<nowiki>Return a Dictionary of all languages supported in system. The dictionary item has key is iso code and value is object {isocode: string, name: string, viewerSupported: bool}</nowiki>}} | ||
}} | }} | ||
+ | === <span style="color:#DF8621">'''Examples'''</span> === | ||
+ | <source lang="javascript"> | ||
+ | // new QuestionnaireTemplate | ||
+ | string qnaireTemplateName = "test"; | ||
+ | number parentId = 17148135; | ||
+ | number resourceTemplateId = 17148218;// 0 to use the default | ||
+ | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaireTemplateName, parentId, resourceTemplateId); | ||
+ | bool increaseStructureVersion = false;//Increase structure version will force reset all QAS sequence | ||
+ | qt.Save(increaseStructureVersion); | ||
+ | //Catglobe.Json.Encode(qt); | ||
+ | </source> | ||
+ | <source lang="javascript"> | ||
+ | //set, get a qnaire property | ||
+ | Questionnaire qnaire = new Questionnaire (17148177); | ||
+ | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); | ||
+ | print(qt.Languages);//{en-GB,da-DK} | ||
+ | LocalizedString a = new LocalizedString ({"": "Completed", "da-DK": "Komplet"}, "en-GB"); | ||
+ | qt.SetProperty(Question_Property_QuestionnaireCompletedText, a); | ||
+ | qt.Save(false); | ||
+ | print(qt.GetProperty(Question_Property_QuestionnaireCompletedText).ToDictionary());//{"": Completed, "da-DK": Komplet} | ||
+ | </source> | ||
+ | <source lang="javascript"> | ||
+ | //Remore an existing qnaire property | ||
+ | Questionnaire qnaire = new Questionnaire (17148177); | ||
+ | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); | ||
+ | qt.SetProperty(Question_Property_QuestionnaireCompletedText, empty); | ||
+ | qt.Save(false); | ||
+ | print(qt.GetProperty(Question_Property_QuestionnaireCompletedText));//empty | ||
+ | </source> | ||
+ | <source lang="javascript"> | ||
+ | //get all existing qnaire properties | ||
+ | Questionnaire qnaire = new Questionnaire (17148177); | ||
+ | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); | ||
+ | print(qt.Properties);//{QuestionnaireProperty,...} | ||
+ | for(i for 0; qt.Properties.Count){ | ||
+ | QuestionnaireProperty p = qt.Properties[i]; | ||
+ | if(p.IsLocalize) | ||
+ | print(p.PropertyTypeAsString +": "+ convertToString(p.Value.ToDictionary())); | ||
+ | else print (p.PropertyTypeAsString +": "+ p.Value); | ||
+ | } | ||
+ | </source> | ||
+ | <source lang="javascript"> | ||
+ | //get an existing question | ||
+ | Questionnaire qnaire = new Questionnaire (17148177); | ||
+ | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); | ||
+ | QuestionTemplate q = qt.GetQuestion("Q1");//return QuestionTemplate or empty if not found | ||
+ | </source> | ||
+ | <source lang="javascript"> | ||
+ | //get all existing questions | ||
+ | Questionnaire qnaire = new Questionnaire (17148177); | ||
+ | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); | ||
+ | print(qt.Questions);//{QuestionTemplate,...} | ||
+ | for(i for 0; qt.Questions.Count){ | ||
+ | QuestionTemplate q = qt.Questions[i]; | ||
+ | print(q.Label); | ||
+ | } | ||
+ | </source> | ||
+ | <source lang="javascript"> | ||
+ | //Delete a question | ||
+ | Questionnaire qnaire = new Questionnaire (17148177); | ||
+ | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); | ||
+ | number index; | ||
+ | for(i for 0; qt.Questions.Count){ | ||
+ | if(qt.Questions[i].Label == "Q1" && !qt.Questions[i].HasData) | ||
+ | index = i; | ||
+ | } | ||
+ | if(index!=empty) | ||
+ | qt.Questions.Remove(qt.Questions[index]); | ||
+ | qt.Save(true); | ||
+ | </source> | ||
+ | <source lang="javascript"> | ||
+ | //get question group | ||
+ | Questionnaire qnaire = new Questionnaire (17148177); | ||
+ | QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId); | ||
+ | qt.Groups;//QuestionGroupRoot | ||
+ | </source> |
Latest revision as of 08:51, 11 May 2022
QuestionnaireTemplate
The questionnaire template.
Parent class
Inherits from object
Constructors
- (int id "Id of questionnaire template") - Fetch exists questionnaire template
- (string qualifiedName "Qualified name of questionnaire") - Fetch exists questionnaire template by name
- (string name "Questionnaire's name", int parentId "Resource parent's id", int resourceTemplateId "Resource tempalte's id of questionnaire template. Set it's 0 to use default resource template") - Create new questionnaire template
Methods
- object GetProperty(PropertyType constant type "Use constant Question_Property_xxxx") - Get value of property type, return empty if not found
- QuestionTemplate GetQuestion(string label "Question label") - Return a question by label or empty if not found
- Empty Save(bool increaseStructureVersion "Increase structure version will force reset all QAS sequence") - Save questionnaire template
- Empty SetProperty(PropertyType constant type "Use constant Question_Property_xxxx", object value "String or LocalizedString depend on property type. If value is empty then the property will be removed") - Set value for property type
- (From object) string ToString() - The string representation of the object.
Properties
- string DefaultLanguage { get; set; } - Gets and sets the default language of this questionnaire. Its value is language iso code
- QuestionGroupRoot Groups { get; } - Information about question groups in questionnaire
- bool HasData { get; } - check if this questionnaire temaplte contains data or not
- int Id { get; } - Reosurce id of questionnaire template
- array Languages { get; } - Active languages associated with this questionnaire. Its value is language iso code
- string Name { get; set; } - Questionnaire template name
- string ObjectTypeName { get; } - The name of the type of object.
- int ParentId { get; set; } - Parent resource's id
- array Properties { get; } - Get configuration properties of this questionnaire template
- string QualifiedName { get; } - Get qualified name of questionnaire name
- array Questions { get; } - Get configuration questions of this questionnaire template
- int ResourceTemplateId { get; set; } - Resource tempalte's id of questionnaire template. Set it's 0 to use default resource template
- int StructureVersion { get; } - Structure version of the questionnaire template. It is increased when updating
- (From object) TypeInformation TypeInformation { get; } - Get information about this class.
- int Version { get; } - Version of the questionnaire template. It is increased when updating
Static Methods
- QuestionnaireTemplate QuestionnaireTemplate_current() - Get questionnaire template in current QAS or PQ context
- Dictionary QuestionnaireTemplate_getActiveLanguages() - Return a Dictionary of all languages supported in system. The dictionary item has key is iso code and value is object {isocode: string, name: string, viewerSupported: bool}
Examples
// new QuestionnaireTemplate
string qnaireTemplateName = "test";
number parentId = 17148135;
number resourceTemplateId = 17148218;// 0 to use the default
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaireTemplateName, parentId, resourceTemplateId);
bool increaseStructureVersion = false;//Increase structure version will force reset all QAS sequence
qt.Save(increaseStructureVersion);
//Catglobe.Json.Encode(qt);
//set, get a qnaire property
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
print(qt.Languages);//{en-GB,da-DK}
LocalizedString a = new LocalizedString ({"": "Completed", "da-DK": "Komplet"}, "en-GB");
qt.SetProperty(Question_Property_QuestionnaireCompletedText, a);
qt.Save(false);
print(qt.GetProperty(Question_Property_QuestionnaireCompletedText).ToDictionary());//{"": Completed, "da-DK": Komplet}
//Remore an existing qnaire property
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
qt.SetProperty(Question_Property_QuestionnaireCompletedText, empty);
qt.Save(false);
print(qt.GetProperty(Question_Property_QuestionnaireCompletedText));//empty
//get all existing qnaire properties
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
print(qt.Properties);//{QuestionnaireProperty,...}
for(i for 0; qt.Properties.Count){
QuestionnaireProperty p = qt.Properties[i];
if(p.IsLocalize)
print(p.PropertyTypeAsString +": "+ convertToString(p.Value.ToDictionary()));
else print (p.PropertyTypeAsString +": "+ p.Value);
}
//get an existing question
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
QuestionTemplate q = qt.GetQuestion("Q1");//return QuestionTemplate or empty if not found
//get all existing questions
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
print(qt.Questions);//{QuestionTemplate,...}
for(i for 0; qt.Questions.Count){
QuestionTemplate q = qt.Questions[i];
print(q.Label);
}
//Delete a question
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
number index;
for(i for 0; qt.Questions.Count){
if(qt.Questions[i].Label == "Q1" && !qt.Questions[i].HasData)
index = i;
}
if(index!=empty)
qt.Questions.Remove(qt.Questions[index]);
qt.Save(true);
//get question group
Questionnaire qnaire = new Questionnaire (17148177);
QuestionnaireTemplate qt = new QuestionnaireTemplate (qnaire.TemplateId);
qt.Groups;//QuestionGroupRoot