In this article
Appendix A - Script Example for Telephone Rotation Scheduling Rules
Procedures and descriptions are provided in the Telephone Rotation Schedule Rules documentation (go to Telephone Rotation Scheduling Rules Overview for more information).
// To initialize 2 required background fields on upload
function InitialiseActiveNumber()
{ var telnumber=GetRespondentValue("Tel1");Scheduling.Interview.TelephoneNumber=telnumber;
SetRespondentValue('TelephoneNumber',telnumber) SetRespondentValue('ActiveTelNumber',"Tel1") SetRespondentValue('ConnectedCallCount', 0);}
// To stop rotation - used for appointment and new number outcomes
function StopRotation() { SetRespondentValue('StopRotation', "1");}
// to update the call history fields after each connected call
// required as the dialer does not go to the survey engine for outcomes that don't connect to an interviewer
(e.g. no reply, busy, fax, etc)
function SaveCallHistory() {var callstatus = Scheduling.Interview.TransientState;
var dt: DateTime = DateTime.Now;
var iter = int(GetRespondentValue('CallAttemptCount')); var currentnumber = GetRespondentValue('ActiveTelNumber');// to increment call count for connected calls only
if (Scheduling.Interview.TransientState == 1 || Scheduling.Interview.TransientState == 33 || Scheduling.Interview.
TransientState == 2 || Scheduling.Interview.TransientState == 3 || Scheduling.Interview.TransientState
== 7 || Scheduling.Interview.TransientState == 7) { SetRespondentValue('Status' + currentnumber, "1"); SetRespondentValue('ConnectedCallCount', int(GetRespondentValue('ConnectedCallCount')) + 1);}
// to incremement count for current number
var currentnumbercount = int(GetRespondentValue('Count' + currentnumber)) SetRespondentValue('Count' + currentnumber, currentnumbercount + 1); SetRespondentValue('LastExtendedStatus', callstatus); f('CallDateTime', iter).setValue(dt); f('CallExtendedStatus', iter).setValue(callstatus); var telno = GetRespondentValue('TelephoneNumber') f('CallPhoneNumber', iter).setValue(telno);Scheduling.Interview.TelephoneNumber = telno;
// To keep track of how many times the number has been called for outcomes Busy / Answer Phone
if (Scheduling.Interview.TransientState == "2" || Scheduling.Interview.TransientState == "7")
SetRespondentValue('ActivePhone', "1"); var activenocount = int(GetRespondentValue('ActiveTelNoCount')) SetRespondentValue('ActiveTelNoCount', activenocount + 1);// IMPORTANT change the limit to the highest number of attempts for busies / answer phones
if (activenocount >= 2 || Scheduling.Interview.TransientState=="8" || Scheduling.Interview.TransientState=="9" || Scheduling.Interview.TransientState == "11") { SetRespondentValue('ActiveTelNoCount', 0); SetRespondentValue('ActivePhone', "0");}
}
// to keep track of how many numbers are still available to call (it excludes unobtainables, faxes, modems)
function UpdateUsablePhoneCount() {var nophones = 6; //**** IMPORTANT Change this if there are more than 6 phone numbers *****
var count: int = 0;
for (var i: int = 1; i <= nophones; i++) { if (GetRespondentValue('Tel' + i) != null && GetRespondentValue('StatusTel' + i)!= 9) {count += 1;
if (GetRespondentValue('StatusTel' + i) == null) { SetRespondentValue('StatusTel' + i, '0');}
}
}
SetRespondentValue('UsablePhoneCount', count);}
// To select to next number available
// Used for rotation when call outcome is a no reply
function SelectNextNumber() { var currNum = GetRespondentValue('ActiveTelNumber');var nextphone;
var phoneArray = ['Tel1', 'Tel2', 'Tel3', 'Tel4', 'Tel5', 'Tel6'] /**** IMPORTANT Add to this if there are more than 6 telephone number background fields */
// to go through all the next numbers
var flagCurr = false;
var rLength = phoneArray.length;
var currArray;
SetRespondentValue('ActiveTelNoCount',0) for (var j: int = 0; j < rLength; j++) {var chkNum = phoneArray[j];
currArray = j;
if (chkNum == currNum) {flagCurr = true;
continue;
}
if (flagCurr) {// test next number to see if TelStatus value is 1 or 9
var testVal = 'Status' + chkNum;
if (GetRespondentValue(testVal) != null && (GetRespondentValue(testVal) == "0" || GetRespondentValue(testVal) == "1")) {nextphone = chkNum;
break;
}
}
}
//end of available phone numbers reached
if (currArray == rLength - 1 && nextphone == null) { for (var jj: int = 0; jj < rLength; jj++) {var chkNum1 = phoneArray[jj];
// test next number to see if TelStatus value is 1 or 9
var testVal1 = 'Status' + chkNum1;
if (GetRespondentValue(testVal1) != null && (GetRespondentValue(testVal1) == "0" || GetRespondentValue(testVal1) == "1")) {nextphone = chkNum1;
break;
}
}
}
if (nextphone) {var nextNum = GetRespondentValue(nextphone);
SetRespondentValue('TelephoneNumber', nextNum);Scheduling.Interview.TelephoneNumber = nextNum;
SetRespondentValue('ActiveTelNumber', nextphone);}
}
// To flag record for rotation
function NextNumberAction() { var usableCount = int(GetRespondentValue('UsablePhoneCount'));// Select next number if ActivePhone is not set to 1 (i.e. for busies and answer phones)
// Remove the second part of the condition if next number should be selected for busies and no replies
if (usableCount > 1 && GetRespondentValue('ActivePhone')!="1") {SelectNextNumber();
}
}
// to flag invalid numbers
function InvalidNumberAction() { var currTelAct = GetRespondentValue('ActiveTelNumber');var tag = 'Status' + currTelAct;
SetRespondentValue(tag, '9');
UpdateUsablePhoneCount();
var usableCount = int(GetRespondentValue('UsablePhoneCount')); if (usableCount > 0) {SelectNextNumber();
} else { SetRespondentValue('ActiveTelNumber', ''); SetRespondentValue('TelephoneNumber', '');Scheduling.Interview.TransientState="32" // all numbers are unobtainable
}
}