Debugging Quotas

When writing quota scripts one of the hardest things to do is to figure out if they will work or not. For a while the only way to test them was to Activate the survey onto the server but very quickly it was realised that a new method was required. In this article we will show you how to set your professional up so that you can debug your quotas scripts on your local machine.

To be able to debug Quotas in professional you will need access to an SQL server. This could be on your local machine, Network Server. In my case I use VMWare. The first thing we need to make sure that we have sorted out is our login setup on the SQL box. Professional uses windows authentication when debugging scripts so you need to make sure that the user you login as on your machine has access to the SQL. If the SQL is a network server then you may need to get IT to set you up with an account. If SQL is on a VMWare machine then you just need to add your windows account name to the SQL box. Not the full name , just the name so if your login was something like “MyDomainjSmith” then all we want in SQL is the “jSmith” bit. They key thing though to all of this , is that the password you use to login to your local machine must be the password you use on the SQL box.

Once you have access to the box Create a database called DebugQuotas and then start up professional. Once you are inside of professional go to the tools / options menu and enter in the name or ip address of your sql machine. and the name of your database that you have access to

Setup Proffesional

Now we are ready to debug our script. The next thing we are going to do is to create a new mdd file. We will call it DebugQuota and it will have the following metadata.

Metadata(en-AU, Question, label)

Colors "What colors do you like ?" categorical [1]
    {
    	Red,Yellow,Pink,Blue,Black,Green
    };

QuotaInfo "{ReplaceMe}" info;

End Metadata

and at this stage this is out routing

Routing(Web)
Dim QuotaPendResult

Colors.ask()

If IOM.Info.IsReview Then
	' Don't pend quotas if the interview is running in review mode.
Else
    ' Quota statements can be executed on the server or in mrStudio
    ' when the mrStudio Debug Quotas option is set
    If Not IsNullObject(QuotaEngine) Then
        ' Pend quotas for a specific quota group
        QuotaPendResult = QuotaEngine.QuotaGroups["Colors"].Pend()
    End If
End If

End Routing

Next we need to create a quota file so click the quota button in professional

Create the MQD file

and you should see the quota program start up. Next you need to drag the colors question into the design area and add your targets to all the cells. We did normal quotas with a target of 10 for each.

Set the Targets

 Once you are done call your quota “Colors” and save your quota file in the same directory as your MDD ( call it “DebugQuota” ) and then close the tool.

Next, click Tools Debug Quotas and if all goes well you will connect to the SQL server and a tick will appear next to the option on the menu. If something goes wrong you will receive an error message. If all is well run you script and see if your Pend Statement gets executed ok. If it does then you can add this next bit of code.

If IOM.Info.IsDebug Then
 For Each oTable in QuotaEngine.QuotaGroups
  sHTML = ""
  sHTML = sHTML + ""
  sHTML = sHTML + ""

  For Each oCell in oTable.Quotas
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
   sHTML = sHTML + ""
  Next
  sHTML = sHTML + "
Table Name : " + oTable.Name + "
IsOverQuota : " + cText(oTable.IsOverQuota) + "
Cell Name : " + oCell.FullName + "
Completed" + ctext(oCell.Completed) + "
Count" + ctext(oCell.Count) + "
ExactPercent" + ctext(oCell.ExactPercent) + "
Expression" + ctext(oCell.Expression) + "
Flag" + ctext(oCell.Flag) + "
Fullname" + ctext(oCell.Fullname) + "
ID" + ctext(oCell.ID) + "
IsBelowQuota" + ctext(oCell.IsBelowQuota) + "
IsOverQuota" + ctext(oCell.IsOverQuota) + "
Metadata" + ctext(oCell.Metadata) + "
Name" + ctext(oCell.Name) + "
OverTargetCount" + ctext(oCell.OverTargetCount) + "
Pending" + ctext(oCell.Pending) + "
PendingPercent" + ctext(oCell.PendingPercent) + "
Target" + ctext(oCell.Target) + "
WasPended" + ctext(oCell.WasPended) + "
"  Next  QuotaInfo.label.Inserts["ReplaceMe"] = sHTML  QuotaInfo.show() End If

Now when you run your code in Professional you will see after the quota is pended a list of tables that show all the values for each quota cell. This is really helpful in showing what has happened and will help with your debugging. So let’s explain the code , well if we take out all the HTML we end up with two loops,

For Each oTable in QuotaEngine.QuotaGroups
' ...
For Each oCell in oTable.Quotas
' .....
Next
Next

So for Each table in the quota group, and by table we mean the name of the table that you add when you use the quota tool , we then loop each cell in the quota and display its values. And there you have it , you have learnt how to debug your quotas and also you have some script that you can use to show the contents of the quota cells when you are debugging your scripts.

Leave a Comment

%d bloggers like this: