Calculating last name from the built-in contact field
I have an App with just the built-in Contact field and an DOB field and need to display the table based on their last name. So I created an Calculated field for it. How do I extract the last name out of the Contact field? @Contact doesn't work. Thanks.
-
Official comment
Hi Bumble,
I'm afraid there wouldn't be a way to do this, since you cannot use Contact fields as variables in a calculation field. Is it possible to store your contacts in an app instead of using Workspace contacts?
https://help.podio.com/entries/27368048-Importing-Contacts-Using-a-Contacts-app
That way you could store first/last names in different fields right from there.
Do you think that could work?
/Jacquelyn - Podio
Comment actions -
Hi Bumble,
if I understand you right, you have a contact field/Type Workspace contacts. There must have benn a misunderstanding by Jacquelyn - or by me) - but that contact field is available as a variable in a calculation field., But only the content of Name field. @contact returns the content as an array, you have to parse it to a string bei adding .join()
To get the name of the contact you can do:
@contact.join()
That shows you the name, how it is entered. Normaly "FirstName LastName" or "FirstName MiddleName LastName".
The LastName you can extract:
var fullname = @contact.join();
fullname.substring(fullname.lastIndexOf(" "));This works fine if there is no suffix like "FirstName LastName, jr." or "FirstName LastName jr.". You can do some checks if there's a suffix.Often a suffix contains a dot or is separated by a comma.
fullname = @contact.join();
getLastString = fullname.substring(fullname.lastIndexOf(" ") );
check = getLastString.indexOf(".") > -1 || fullname.indexOf(",") > -1 ? fullname.substring(0,fullname.lastIndexOf(" ")) : fullname;
lastname = check.substring(check.lastIndexOf(" "));
lastname.replace(",","")This doesn't cover all possible cases , e.g. for a name entered as "FirstName LastName junior" the result would be "junior" or for "LastName Firstname" = FirstName, but the result for "LastName, FirstName" would be "LastName"
Rainer
rg@delos-consulting.com -
@helge
Have a look at the date of Jacquelyn's answer: July 16, 2014
The calculation fields have been introduced some weeks before, in May 2014 (if I remember right). And at that time not all field types have been available in calculation fields. E.g. Contacts have been added a bit later. So for July 16, 2014 Jacquelyn's answer has been correct.Rainer
Please sign in to leave a comment.
Comments
5 comments