Sorry i missed that one, good you spotted that error.
Thanks
Announcement
Collapse
No announcement yet.
Retrieve type from phone number
Collapse
X
-
An error has crept into your code.
I only noticed it when I had a contact with just a landline number and no mobile number.
} else {
whatsapp = null;
handynummervorhanden = null; <- false must be entered here, not null
-
Of course it can be copied. That's what the forum is for, to exchange information.
You don't have to use WhatsApp. You can use any app.
I would have liked to use Telegram, but it's by username and not by cell phone number.
-
Are you combining this with Kharg: https://forum.espocrm.com/forum/exte...ge2#post104838 ?
Sound like I need to copy this idea, too bad we don't use WhatApp in our country often enough
-
may be try this
PHP Code:while ($i < array\length(phoneNumberData)) {
$type = object\get(array\at(phoneNumberData, $i), 'type');
if ($type == 'Mobile') {
$mobile = object\get(array\at(phoneNumberData, $i), 'phoneNumber');
if ($mobile) {
whatsapp = string\concatenate('https://wa.me/', $mobile);
handynummervorhanden = true;
}
break;
} else {
whatsapp = null;
handynummervorhanden = null;
}
$i = $i + 1;
}
Last edited by rabii; 04-15-2024, 11:32 AM.
- Likes 3
Leave a comment:
-
Thank you
your script does exactly what I had in mind.
My script now looks like this:
PHP Code:$i = 0;
while ($i < array\length(phoneNumberData)) {
$type = object\get(array\at(phoneNumberData, $i), 'type');
if ($type == 'Mobile') {
$mobile = object\get(array\at(phoneNumberData, $i), 'phoneNumber');
break;
}
$i = $i + 1;
}
ifThenElse($mobile != null, whatsapp=string\concatenate('https://wa.me/', $mobile), whatsapp = null);
ifThenElse($mobile != null, handynummervorhanden = true, handynummervorhanden = false);
Now I have added a bool field, if mobile exists, then it will be set to true.
So that I can check whether a mobile number is available and show the button, otherwise hide it.
I actually wanted to shorten the formula, but the following formula didn't work somehow:
PHP Code:ifThenElse($mobile != null, whatsapp=string\concatenate('https://wa.me/', $mobile) && handynummervorhanden = true, whatsapp = null && handynummervorhanden = false);
- Likes 1
Leave a comment:
-
Hi ChrisSka83
Try this code, it should work
PHP Code:$i = 0;
while ($i < array\length(phoneNumberData)) {
$type = object\get(array\at(phoneNumberData, $i), 'type');
if ($type == 'Mobile') {
$mobile = object\get(array\at(phoneNumberData, $i), 'phoneNumber');
break;
}
$i = $i + 1;
}
The code simply iterate through the phone number data and if a mobile type exists then it will be assigned to a $mobile variable and it will break the loop.
- Likes 1
Leave a comment:
-
-
Hi ChrisSka83,
You can get the primary phone number Type value using the following formula script (using the last line you can test it in Administration > Formula Sandbox by selecting any contact):
Code:$phoneNumberData = json\encode(phoneNumberData); $phoneNumberType = json\retrieve($phoneNumberData, string\concatenate(0, '.type')); output\printLine($phoneNumberType);
Code:$phoneNumbersCount = array\length(phoneNumberData); $phoneNumberData = json\encode(phoneNumberData); $i = 0; while ($i < $phoneNumbersCount) { $phoneNumberType = json\retrieve($phoneNumberData, string\concatenate($i, '.type')); $phoneNumbersTypesArray = array\push($phoneNumbersTypesArray, $phoneNumberType); $i = $i + 1; } $phoneNumbersTypes = array\join($phoneNumbersTypesArray, '\n'); output\printLine($phoneNumbersTypes);
- Likes 1
Leave a comment:
-
Hi, You can check in phoneNumberData. It's an array of objects. An item contains information for a single email address.
Leave a comment:
-
Retrieve type from phone number
Hello everyone,
does anyone have any idea how I can read the type of phone number from the contacts?
The idea behind it:
I want to create a whatsapp button in the contact entity, but only if the phone number is a cell phone number.
If it is a cell phone number, then a formula should write the link in the button.
If it is another number, e.g. a landline number, then it should not write anything.
I use the link button extension from Kharg .
With this formula it only writes the first number:
ifThenElse(phoneNumber != null, whatsapp=string\concatenate('https://wa.me/', phoneNumber), whatsapp = null);Last edited by ChrisSka83; 04-15-2024, 12:01 AM.Tags: None
- Likes 1
Leave a comment: