This how-to will introduce you to the functions of QuotaMgr.
These set of functions allow you to communicate with your quotas throughout your scripts, dynamically while an interview is conducted.
This might come in handy when the script logics are quota dependent.
The QuotaMgr functions:
- QuotaMgr.GetQuotaCurrent(“name of your quota”);
This function will get the current number filled by the given quota name.
- QuotaMgr.GetQuotaTotal(“name of your quota”);
This function will get the current target of the given quota name.
This function will return ‘true’ if the current interview has set the given quota and ‘false’ if it hasn’t.
This function will return ‘true’ if the current quota is full and ‘false’ if it isn’t full.
You can use these functions in any script, but please note, that the quota name must be exactly as it is written in your quota configuration’s, if it is not the same, it would not work.
Quotas Functions and Multiple Languages
As the quotas functions rely on the quota name as an input parameter, additional scripting work will sometimes be required when having a script with multiple languages (Click Here to learn on Multiple Languages in SurveyToGo).
Most of the times when using quotas functions, the relevant quotas names to be sent as parameters are dynamically pulled (and are not written "hard-coded" in the script). For example: Let's say there's a Gender question (index 1) with two answer options: "Male" and "Female", and this question is part of the quotas structure. And let's say that in my script I want to check if the quota of the selected answer in that gender question is already filled or not. As the answer selection is dynamic during the interview, I don't know what answer will be chosen and so I do not know what is the name of the quota I want to check (it can be either "Male" or "Female"). So, the code to get the quota name dynamically would be this:
And so the full code to check if the quota of the selected answer is filled would be this:
Now, when working with multiple languages, mismatches occur between answers texts and the actual quotas names. While answers texts are translated and appear in languages other than the default, the quotas names in the system are not translated, those would stay in the default language.
To solve this "mismatch" and avoid code failure, make sure to get the ORIGINAL DEFAULT text of the answer, like this:
GetAnswerOriginalText(QRef(1), Answer(QRef(1)), true, LanguageMgr.DefaultLanguageID);
The above will return the original text of the answer as was written in the default language and so as matches the quota's name as well.
Visit us at: http://www.dooblo.net