Professional > Interview scripting > Writing interview scripts > Quota control scripting > Prioritizing quota cells for multiple choice answers > Pending a number of cells using prioritization
 
Pending a number of cells using prioritization
This topic takes the simple example of pending a single cell (see Pending one cell only using prioritization) and extends it to work with a number of pended cells. Instead of asking respondents to choose their favorite flavor from one brand, the script now asks them to choose flavors for a number of brands. The number of brands is set in the PendLimit variable in the QUOTA_Matrix table.
The metadata section of the script now has the Flavor question displayed as a grid, with one column for each brand pended. It also has a PendedBrands question that is used in the routing section to filter the brand list for the grid so that it contains only the pended brands. (In the example of pending one cell only, PendedBrands was a simple variable that was used for display purposes only.)
Brands define
{
Alpine,
HelenB "Helen Bradley's",
DFresh "Dairy Fresh",
Kentish "Kentish Farm",
Finborough,
Alsace
};
IceCream "Which brands of ice cream do you buy?" categorical [1..]
{use Brands};
PendedBrands "Brands pended." categorical [1..]
{use Brands};
FlavorGrid "Which are your favorite flavors in the following brands
of ice cream?" loop
{use Brands} fields
(
Flavor "" categorical [1..1]
{
Chocolate, Mint,
Toffee "Toffee crunch",
Raspberry "Raspberry ripple",
Strawberry "Strawberry",
Vanilla "Vanilla",
OtherFlavor "Other"
};
) column expand grid;
AllFull "All our interviewing targets have been met. I'm sorry to
have troubled you." info;
The routing code that pends the least full cell and then selects that brand as the filter for the Flavor question is:
IceCream.Ask()
'Terminate interviews where no cells can be pended
If Not _
(PendQuotas(IceCream, PendedBrands, QuotaEngine.QuotaGroups["IceCream"])) _
Then
IOM.Texts.InterviewStopped = AllFull.Label
IOM.Terminate(Signals.sigOverQuota)
End If
FlavorGrid.QuestionFilter = PendedBrands.Response.Value
FlavorGrid.Ask()

' Pend quotas and return names of pended brands
Function PendQuotas(QuotaQuestion, CellsPended, QuotaGroupToPend)
Dim pend_result
' Initialize return to False
PendQuotas = False
' Pend quotas
pend_result = QuotaGroupToPend.Pend()
If (IsSet(pend_result, QuotaResultConstants.qrWasPended)) Then
' Save the pended cell information
CellsPended.Response.Value = _
CreateFilter(CellsPended.Categories, QuotaGroupToPend.Quotas)
PendQuotas = True
End If
End Function

' Build list of names of pended brands
Function CreateFilter(Categories, Quotas)
Dim pended_quota, filter
For Each pended_quota In Quotas.WasPendedList
filter = filter + GetCategoryFromQuota(Categories, pended_quota)
Next
CreateFilter = filter
End Function

' Get category names of pended brands
Function GetCategoryFromQuota(Categories, Quota)
Dim category
GetCategoryFromQuota = "{}"
For Each category in Categories
If (Find(Quota.Expression, "{" + category.Name + "}") >= 0) Then
GetCategoryFromQuota = CCategorical(category)
Exit Function
End If
Next
End Function
The comments in the script summarize what it does. The metadata requires respondents to answer additional questions about certain brands that they have mentioned. Which brands these are depends on the type of prioritization you are using, how many cells you want to pend, and whether the quotas are still open for any of the brands mentioned. The script covers all these points.
The return value of the PendQuotas function determines whether the interview can continue past the first question. If the function returns False, no quotas could be pended and the interview is terminated.
If PendQuotas pends any cells, it calls the CreateFilter function to assign the corresponding responses to the PendedBrands question. This question is used as a filter for FlavorGrid so that the grid contains columns for just the pended brands. The response names are extracted by the GetCategoryName function, which takes each category in the BrandsPended response list in turn and compares it with the descriptions of the pended quota cells. When a match is found, the function converts the name into a category number so that it can be assigned as a response in the usual way.
See also
Prioritizing quota cells for multiple choice answers