I wrote a function which formats phone numbers; if I take off the transform script the number appears on the sitemap (unformatted as expected; with the transform it is empty):
(function(phoneNumber){
// 170305 MaxG: format phone numbers
var result;
if (phoneNumber.substr(0, 1) == "0") {
phonePrefix = phoneNumber.substr(1, 1);
switch (phonePrefix) {
case "4":
result = phoneNumber.replace(/((\d{4})(\d{3})(\d{3}))/g, '$2 $3 $4');
break;
default:
result = phoneNumber.replace(/((\d{2})(\d{4})(\d{4}))/g, '$2 $3 $4');
}
} else {
if (phoneNumber.substr(0, 1) == "1") {
phoneNumberLength = phoneNumber.length;
switch (phoneNumberLength) {
// (6) 13 13 13; (10) 1300 123 456; 1800 123 456
case 6:
result = phoneNumber.replace(/((\d{2})(\d{2})(\d{2}))/g, '$2 $3 $4');
break;
case 10:
result = phoneNumber.replace(/((\d{4})(\d{3})(\d{3}))/g, '$2 $3 $4');
break;
default:
result = phoneNumber;
}
}
}
return result
})(input)
called in items like so:
String fBox_LastCallerNumber "Last caller's number [JS(fb_phoneNumber.js):%s]" <phone>
I tested this as JavaScript (the same as above without the OH wrapper) which works:
// test code; works
number ="0411511332";
number ="0754286595";
number ="1300511002";
number ="131213";
function phoneNumber(number){
// 170305 MaxG: format phone numbers
var result;
if (phoneNumber.substr(0, 1) == "0") {
phonePrefix = phoneNumber.substr(1, 1);
switch (phonePrefix) {
case "4":
result = phoneNumber.replace(/((\d{4})(\d{3})(\d{3}))/g, '$2 $3 $4');
break;
default:
result = phoneNumber.replace(/((\d{2})(\d{4})(\d{4}))/g, '$2 $3 $4');
}
} else {
if (phoneNumber.substr(0, 1) == "1") {
phoneNumberLength = phoneNumber.length;
switch (phoneNumberLength) {
// (6) 13 13 13; (10) 1300 123 456; 1800 123 456
case 6:
result = phoneNumber.replace(/((\d{2})(\d{2})(\d{2}))/g, '$2 $3 $4');
break;
case 10:
result = phoneNumber.replace(/((\d{4})(\d{3})(\d{3}))/g, '$2 $3 $4');
break;
default:
result = phoneNumber;
}
}
}
return result
}
I can’t find any mistake; any hints appreciated.
the log shows:
2017-07-20 13:04:37.181 [INFO ] [o.o.b.f.i.FritzboxTr064Binding] - found name match Max in phonebook by comparing 2001151140 with 2001151
2017-07-20 13:04:37.232 [INFO ] [.model.script.fbLastCall1.rule] - Call coming in...
2017-07-20 13:04:37.254 [INFO ] [.model.script.fbLastCall2.rule] - tmpLastCallerNumber..:
2017-07-20 13:04:37.271 [INFO ] [.model.script.fbLastCall3.rule] - tmpName..............: Max (Mobile)
2017-07-20 13:04:37.276 [INFO ] [.model.script.fbLastCall4.rule] - tmpNumber............:
2017-07-20 13:04:37.298 [INFO ] [.model.script.fbLastCall5.rule] - fBox_LastCallerName..: fBox_LastCallerName (Type=StringItem, State=Max (Mobile))
2017-07-20 13:04:37.309 [INFO ] [.model.script.fbLastCall6.rule] - fBox_LastCallerNumber: fBox_LastCallerNumber (Type=StringItem, State=)
2017-07-20 13:04:42.284 [INFO ] [o.o.b.f.i.FritzboxTr064Binding] - Trying to resolve number 0411511332 to name comparing 7 characters
the rule going with it:
rule "Fritzbox: Incoming call, get number and name from phonebook"
when
Item fbox_Ringing changed from OFF to ON
then
logInfo("fbLastCall1.rule", "Call coming in...")
// get incoming call data (array)
val CallType InCall = fbox_IncomingCall.state as CallType
val String tmpLastCallerNumber = InCall.destNum.toString()
var String tmpLastCallerName = fbox_IncomingCallResolved.state.toString()
logInfo("fbLastCall2.rule", "tmpLastCallerNumber..: {}", tmpLastCallerNumber)
// remove the called (own) number from caller string
tmpLastCallerName = tmpLastCallerName.removeStart("0754286585##")
if(tmpLastCallerName.startsWith("Name not found for")) {
tmpLastCallerName = "Unknown"
}
logInfo("fbLastCall3.rule", "tmpName..............: {}", tmpLastCallerName)
logInfo("fbLastCall4.rule", "tmpNumber............: {}", tmpLastCallerNumber)
// update name and number
fBox_LastCallerName.postUpdate(tmpLastCallerName)
fBox_LastCallerNumber.postUpdate(tmpLastCallerNumber)
logInfo("fbLastCall5.rule", "fBox_LastCallerName..: {}", fBox_LastCallerName)
logInfo("fbLastCall6.rule", "fBox_LastCallerNumber: {}", fBox_LastCallerNumber)
end