Description:
Whilst working on an automated test for
Ti.Contacts.Person properties, an issue was found when attempting to retrieve the properties using
Ti.Contacts.getPeopleWithName. fields with single string values were returned as intended, however fields with arrays such as
email do not return the correct value (i.e.
[object Object] or an error with be thrown using the following code:
Ti.API.info("person: " + person.email.home[0]); )
However, a workaround to this issue is to use the method
Ti.Contacts.getPersonByIdentifier , which correctly returns fields with array values.
Confirmed that this is *not* a regression.
Steps to reproduce:
1. Create a new Classic project.
2. use demo code:
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'
});
var saveID = "";
var Ncook = new Object();
Ncook.firstName = "Nathaniel";
Ncook.lastName = "Cook";
Ncook.middleName = "John";
Ncook.nickname = "Fish";
Ncook.prefix = "Mr";
Ncook.suffix = "III";
Ncook.firstPhonetic = "N";
Ncook.middlePhonetic = "T";
Ncook.lastPhonetic = "A";
Ncook.organization = "appcelerator";
Ncook.department = "Cloud";
Ncook.jobTitle = "QE";
Ncook.note = "You gotta risk it, to get the biscuit";
Ncook.email = {
home : [
'myGmail',
'myHotmail'
],
work : [
'myWorkemail'
]
};
// Ncook.address = "";
// Ncook.phone = "";
// Ncook.instantMessage = "";
// Ncook.relatedNames = "";
// Ncook.date = "";
// Ncook.url = "";
var singleValue = [
'firstName', 'lastName', 'middleName', 'nickname', 'prefix', 'suffix', 'firstPhonetic', 'middlePhonetic', 'lastPhonetic', 'organization','department', 'jobTitle', 'note'
];
var multiValue = [
'email', 'address', 'phone', 'instantMessage', 'relatedNames', 'date', 'url'
];
newNathan = Ti.UI.createButton({
title: "New Nathan",
top: '20%'
});
newNathan.addEventListener('click', function(){
var newCook = Ti.Contacts.createPerson(Ncook);
// saveID = newCook.getIdentifier();
// Ti.API.info(saveID);
});
button2 = Ti.UI.createButton({
title: "Compare Nathan",
top: '40%'
});
button2.addEventListener('click', function(){
var people = Ti.Contacts.getPeopleWithName("Nathaniel");
// var people = Ti.Contacts.getPersonByIdentifier(saveID);
Ti.API.info('Total contacts: ' + people.length);
var person = people[0];
// var person = people;
Ti.API.info("Ncook: " + Ncook.email.home[0]);
Ti.API.info("person: " + person.email);
//Ti.API.info("person: " + person.email.home[0]);
Ti.API.info("person: " + person.lastName);
Ti.API.info("-----------------------------------------");
for (var j=0, jlen=singleValue.length; j<jlen; j++){
if(Ncook[singleValue[j]] == person[singleValue[j]] && Ncook[singleValue[j]] != null) {
Ti.API.info(singleValue[j] + ': ' + 'Success!');
} else {
Ti.API.info('No Match');
}}
for (var i=0, jlen=multiValue.length; i<jlen; i++){
if(Ncook[multiValue[i]] == person[multiValue[i]] && Ncook[multiValue[i]] != null) {
Ti.API.info(multiValue[i] + ': ' + 'Success!');
} else {
Ti.API.info('No Match');
}}
});
win1.add(button2);
win1.add(newNathan);
win1.open();
3. Build to device.
4. launch app and click "New Nathan" followed by "Compare Nathan"
5. In the console, "Ncook" should return the appropriate email value, "person" will not.
Result:
calling fields with array values using
Ti.Contacts.GetPeopleWithName will not return the appropriate values.
Expected Result:
calling fields with array values using
Ti.Contacts.GetPeopleWithName will return the appropriate values.
reminder to check for parity with android and windows.
[~htbryant] The person objects returned by
Ti.Contacts.GetPeopleWithNameare not JSON objects. So a subscripting likeperson[multiValue[ i ]]will not work. This should be accessed asperson.emailorperson.phoneetc. Also can you provide the test case which is working withTi.Contacts.getPersonByIdentifier[~ssombhatla] I have also tested that way as well, if you refer to line 76 - 79 of the test code, I have created prints to logs of specific property values -
Ncookbeing the original object, andpersonbeing the object retrieved from contacts withgetPeopleWithNamethat was created withTi.Contacts.getPeopleWithName("Nathaniel"). If you check the console above the loop output, you should find thatTi.API.info("person: " + person.email)is not returning what is expected. The test case forTi.Contacts.getPersonByIdentifierrequires the same steps as the above, with the following code:*To be run on a iOS 9 device* In regards to the console statements printingvar win1 = Titanium.UI.createWindow({ title:'Tab 1', backgroundColor:'#fff' }); var saveID = ""; var Ncook = new Object(); Ncook.firstName = "Nathaniel"; Ncook.lastName = "Cook"; Ncook.middleName = "John"; Ncook.nickname = "Fish"; Ncook.prefix = "Mr"; Ncook.suffix = "III"; Ncook.firstPhonetic = "N"; Ncook.middlePhonetic = "T"; Ncook.lastPhonetic = "A"; Ncook.organization = "appcelerator"; Ncook.department = "Cloud"; Ncook.jobTitle = "QE"; Ncook.note = "You gotta risk it, to get the biscuit"; Ncook.email = { home : [ 'myGmail', 'myHotmail' ], work : [ 'myWorkemail' ] }; // Ncook.address = ""; // Ncook.phone = ""; // Ncook.instantMessage = ""; // Ncook.relatedNames = ""; // Ncook.date = ""; // Ncook.url = ""; var singleValue = [ 'firstName', 'lastName', 'middleName', 'nickname', 'prefix', 'suffix', 'firstPhonetic', 'middlePhonetic', 'lastPhonetic', 'organization','department', 'jobTitle', 'note' ]; var multiValue = [ 'email', 'address', 'phone', 'instantMessage', 'relatedNames', 'date', 'url' ]; newNathan = Ti.UI.createButton({ title: "New Nathan", top: '20%' }); newNathan.addEventListener('click', function(){ var newCook = Ti.Contacts.createPerson(Ncook); saveID = newCook.getIdentifier(); Ti.API.info(saveID); }); button2 = Ti.UI.createButton({ title: "Compare Nathan", top: '40%' }); button2.addEventListener('click', function(){ // var people = Ti.Contacts.getPeopleWithName("Nathaniel"); var people = Ti.Contacts.getPersonByIdentifier(saveID); Ti.API.info('Total contacts: ' + people.length); // var person = people[0]; var person = people; Ti.API.info("Ncook: " + Ncook.email.home[0]); Ti.API.info("person: " + person.email.home[0]); Ti.API.info("person: " + person.lastName); Ti.API.info("-----------------------------------------"); for (var j=0, jlen=singleValue.length; j<jlen; j++){ if(Ncook[singleValue[j]] == person[singleValue[j]] && Ncook[singleValue[j]] != null) { Ti.API.info(singleValue[j] + ': ' + 'Success!'); } else { Ti.API.info('No Match'); }} for (var i=0, jlen=multiValue.length; i<jlen; i++){ if(Ncook[multiValue[i]] == person[multiValue[i]] && Ncook[multiValue[i]] != null) { Ti.API.info(multiValue[i] + ': ' + 'Success!'); } else { Ti.API.info('No Match'); }} }); win1.add(button2); win1.add(newNathan); win1.open();person.email.home[0]), should it not be able to retrieve the appropriate data with the methodTi.Contacts.GetPeopleWithName, as it does withTi.Contacts.getPersonByIdentifier? Let me know if you any more queries.I checked on android with the code above & I see that
emailreturns[object object]which in code is accessed asperson.emailEnvironment: Appc Studio : 4.4.0.201511241829 Ti SDK : 5.1.2.v20151215104446 Ti CLI : 5.0.5 Alloy : 1.7.26 MAC Yosemite : 10.10.5 Appc NPM : 4.2.2 Appc CLI : 5.1.0 Node: v0.12.27 Samsung Galaxy S4 - Android 5.0.1[~htbryant] Thanks for providing additional info. I observe that the original app.js file is wrongly using
Ti.API.info("person: " + person.email)at line 70. But the app.js withTi.Contacts.getPersonByIdentifieris correctly usingTi.API.info("person: " + person.email.home[0]). Sinceperson.emailreturns JSON it prints [object Object]. Or you can tryTi.API.info("person: " + JSON.stringify(person.email))to see the complete JSON structure.[~ssombhatla] Thanks for the clarification, found the issue was with the contacts in the device, and was due to user error. Using
JSON.stringify(person.email))revealed that. closing ticket as invalid.