Derivation using a callback script
With the callback script rules in Askia, you can set as many different rules as you want, from a single script.
You have the option to store phone numbers in several fields.
By way of example, let's imagine you have five fields with telephone numbers that could be used in a CATI project. For some contacts, you could have a single phone number (id=1) and for another contact you have five numbers (id=2).
The most important thing is to have one field set as the default phone number 'TEL_TO_DIAL'.
This field will be used as the [Contact.Phone] default system and will be used by the call back rules by script.
In our example, we have duplicated all fields with a phone number in order to keep the original phone number and delete the wrong phone numbers.
For example, if TEL1_A is a wrong number, the TEL1_B will be deleted.
Id | TEL_TO_DIAL | TEL1_A | TEL1_B | TEL2_A | TEL2_B | TEL3_A | TEL3_B | TEL4_A | TEL4_B | TEL5_A | TEL5_B |
1 | 00331111111 | 00331111111 | 00331111111 | ||||||||
2 | 00441111112 | 00441111112 | 00441111112 | 00442211113 | 00442211113 | 00443311112 | 00443311112 | 00444411112 | 00444411112 | 00445511112 | 00445511112 |
3 | 00391111113 | 00391111113 | 00391111113 | 0039441113 | 0039441113 | 0039525113 | 0039525113 |
If you want to apply the rules on all lists allocated to the survey, select the task properties and add your script as follows:
Delete wrong numbers . . .
'------------------------delete wrong numbers------------------
If [CallHistory.LastCallResult] = 8 then
if ([Contact.Phone]= [ListFields.TEL1_A]) then
[ListFields.TEL1_B]= " "
end if
if ([Contact.Phone]= [ListFields.TEL2_A]) then
[ListFields.TEL2_B]= " "
end if
if ([Contact.Phone]= [ListFields.TEL3_A]) then
[ListFields.TEL3_B]= " "
end if
if ([Contact.Phone]= [ListFields.TEL4_A]) then
[ListFields.TEL4_B]= " "
end if
if ([Contact.Phone]= [ListFields.TEL5_A]) then
[ListFields.TEL5_B]= " "
end if
end if
NB : Set the max attempts for wrong number to 5 in the Callback tab
Select the cases:
We declare a variable 'arrCalltoderiv' = 1 if we can derive, 0 else
We set the cases where we have to derive:
- Busy (2)
- No answer (3)
- Answering machine (5)
- Wrong number (8)
- Fax (11)
- etc
'-------------------------select the case----------------
Dim arrCalltoderiv
arrCalltoderiv=0
if [Contact.CallCount] > 0 then
Select Case [CallHistory.LastCallResult]
Case 2, 3, 5, 8, 11
arrCalltoderiv =1
case else
arrCalltoderiv =0
end Select
end if
Remove a phone number with an empty field . . .
We declare the variable 'validPhone(5)' that will contain valid phone number fields - we want to remove empty fields, where 5 is the maximum number of phone fields:
'----------------------------list of fields with phone number-----------------
dim Ntel(5)
Ntel(1) = [ListFields.TEL1_B]
Ntel(2) = [ListFields.TEL2_B]
Ntel(3) = [ListFields.TEL3_B]
Ntel(4) = [ListFields.TEL4_B]
Ntel(5) = [ListFields.TEL5_B]
' -------------------------list of valid phone numbers ------------------------------
dim validPhone(5)
dim validPhoneIndex
validPhoneIndex = 1
dim z
For z = 1 to 5
If len(Ntel(z))> 2 Then
validPhone(validPhoneIndex) = Ntel(z)
validPhoneIndex = validPhoneIndex + 1
End If
Next
If ValidPhoneIndex > 1 Then
validPhoneIndex = validPhoneIndex - 1
' Counter act the last loop
' The IF statement is to prevent the index to be ZERO when
' no Ntel phone numbers exist.
else
ValidPhoneIndex = 1
End If
'--------------------last call phone number--------------------------------------------
Dim currPhone
currPhone = [CallHistory.LastCallPhone]
'--------------------Phone number to use for the next call-------------------------
Dim newPhone
Dim listPrefix
listPrefix= "05" 'Number prefix set on your list
Dim k
For k = 1 To validPhoneIndex ' <-- validPhone.length in VBScript
' (k mod validPhoneIndex ) + 1
' when k is equal to 6 (six valid phone numbers)
' this formula produces:
' 1->2
' 2->3
' 3->4
' 4->5
' 5->1
If currPhone = listPrefix & validPhone(k) Then
newPhone = validPhone( (k mod validPhoneIndex ) + 1 )
End If
Next
if newPhone="" then
newPhone = validPhone(1)
end if
'--------if no anymore phone number are available
if len(validPhone(1))<1 then
[Result.IsOverCallback]= true
end if
And finally, fill the [Contact.Phone] with the number to dial for the next call.
- If you are using an external database, the field to change is the field declared as the default phone number field.
'-------------Fill the Contact.Phone for the next call---------------------------------
if arrCalltoderiv = 1 then
[ListFields.TEL_TO_DIAL] = newPhone ' when we use an external database
end if
- If you are using a list, the field to change is the [contact.phone]:
'-------------Fill the Contact.Phone for the next call---------------------------------
if arrCalltoderiv = 1 then
[Contact.Phone]=newPhone ' when we use a list
end if
If you want to run this example, we have enclosed a package (📥 All_KB_Derivation_By_Script.tsk) that you can import into your system.