Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20152] iOS: Contacts.getPeopleWithName not returning multi-value fields correctly

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2016-02-16T06:34:10.000+0000
Affected Version/sRelease 5.1.1
Fix Version/sn/a
ComponentsiOS
Labelsqe-5.1.2
ReporterHarry Bryant
AssigneeSrikanth Sombhatla
Created2015-12-17T01:33:18.000+0000
Updated2016-02-16T06:34:15.000+0000

Description

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.

Comments

  1. Chee Kiat Ng 2015-12-17

    reminder to check for parity with android and windows.
  2. Srikanth Sombhatla 2015-12-17

    [~htbryant] The person objects returned by Ti.Contacts.GetPeopleWithName are not JSON objects. So a subscripting like person[multiValue[ i ]] will not work. This should be accessed as person.email or person.phone etc. Also can you provide the test case which is working with Ti.Contacts.getPersonByIdentifier
  3. Harry Bryant 2015-12-17

    [~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 - Ncook being the original object, and person being the object retrieved from contacts with getPeopleWithName that was created with Ti.Contacts.getPeopleWithName("Nathaniel") . If you check the console above the loop output, you should find that Ti.API.info("person: " + person.email) is not returning what is expected. The test case for Ti.Contacts.getPersonByIdentifier requires the same steps as the above, with the following 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.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();
       
    *To be run on a iOS 9 device* In regards to the console statements printing person.email.home[0]) , should it not be able to retrieve the appropriate data with the method Ti.Contacts.GetPeopleWithName , as it does with Ti.Contacts.getPersonByIdentifier ? Let me know if you any more queries.
  4. Lokesh Choudhary 2015-12-17

    I checked on android with the code above & I see that email returns [object object] which in code is accessed as person.email Environment: 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
  5. Srikanth Sombhatla 2015-12-21

    [~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 with Ti.Contacts.getPersonByIdentifier is correctly using Ti.API.info("person: " + person.email.home[0]). Since person.email returns JSON it prints [object Object]. Or you can try Ti.API.info("person: " + JSON.stringify(person.email)) to see the complete JSON structure.
  6. Harry Bryant 2015-12-21

    [~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.

JSON Source