Problem with saving some Contact's fields to phone's contacts


#1

Dear all,

I am really new to ionic and cordova, I am building an application (employee contact list).

using this method from ngCordova:

$scope.saveContact = function(contactForm){
    $cordovaContacts.save(contactForm).then(function(result) {
      MessageService.alertSuccess("Contact has been saved successfully!");
    }, function(err) {
      console.log("Something went wrong: "+err);
      MessageService.alertError("Something went wrong, with adding contact list: "+ err);
    });
  };

And it is working for some fields, and not for other fields

:smile: Here is fields that are working:

$scope.contactForm.displayName = employee.get('username');

    var phoneNumbers = [];
    phoneNumbers[0] = new ContactField('phoneNumbers', employee.get('mobilePhone'));
    phoneNumbers[1] = new ContactField('phoneNumbers', employee.get('phone'));
    $scope.contactForm.phoneNumbers = phoneNumbers;

:persevere: And here fields that are not working:

var addresses = new ContactAddress();
    addresses.pref = true;
    addresses.type = "Home";
    addresses.formatted = employee.get('streetAddress') + ", "+ employee.get('stateOrProvince')+ ", " + employee.get('city')+ ", " +employee.get('countryOrRegion');
    addresses.streetAddress = employee.get('streetAddress');
    addresses.locality = employee.get('city');
    addresses.region = employee.get('stateOrProvince');
    addresses.postalCode = employee.get('postalCode');
    addresses.country = employee.get('countryOrRegion');
    $scope.contactForm.addresses = addresses;

    

    var organizations = [];
    organizations.pref = true;
    organizations.type = "Company";
    organizations.name = employee.get('company');
    organizations.department = employee.get('department');
    organizations.title = employee.get('title');
    $scope.contactForm.organizations = organizations;

What wrong with my code, why they are not Saved to contact list?


#2

Even i have been facing the same problem. when i save only the display name gets saved and nothing else.

Did you find any solution yet.?


#3

beside displayname I have this fields working as well like phone and email I guess,
NOTE: But it is sad that the displayName is not working in ios, only for android :frowning:

AND I haven’t solve this yet, sorry

$scope.contactForm.displayName = employee.get(‘username’);

var phoneNumbers = [];
phoneNumbers[0] = new ContactField('phoneNumbers', employee.get('mobilePhone'));
phoneNumbers[1] = new ContactField('phoneNumbers', employee.get('phone'));
$scope.contactForm.phoneNumbers = phoneNumbers;

#4

I think that addresses should be an array.

Try:

var address = new ContactAddress();
addresses.pref = true;
addresses.type = "Home";
addresses.formatted = employee.get('streetAddress') + ", "+ employee.get('stateOrProvince')+ ", " + employee.get('city')+ ", " +employee.get('countryOrRegion');
addresses.streetAddress = employee.get('streetAddress');
addresses.locality = employee.get('city');
addresses.region = employee.get('stateOrProvince');
addresses.postalCode = employee.get('postalCode');
addresses.country = employee.get('countryOrRegion');
$scope.contactForm.addresses = [address];

#5

#=================Tutorial================

I wrote a tutorial on how to use ngCordova Contacts plugin to create, find, and delete contacts. You will also find a working example.

##Click here to open a tutorial including working examples

If you’re only interested into contact object you can use to save contact data you can use this one:

	$scope.contact = {     // We will use it to save a contact

		"displayName": "Gajotres",
		"name": {
			"givenName"  : "Dragan",
			"familyName" : "Gaic",
			"formatted"  : "Dragan Gaic"
		},
		"nickname": 'Gajotres',
		"phoneNumbers": [
			{
				"value": "+385959052082",
				"type": "mobile"
			},
			{
				"value": "+385914600731",
				"type": "phone"
			}				
		],
		"emails": [
			{
				"value": "dragan.gaic@gmail.com",
				"type": "home"
			}
		],
		"addresses": [
			{
				"type": "home",
				"formatted": "Some Address",
				"streetAddress": "Some Address",
				"locality":"Zagreb",
				"region":"Zagreb",
				"postalCode":"10000",
				"country":"Croatia"
			}
		],
		"ims": null,
		"organizations": [
			{
				"type": "Company",
				"name": "Generali",
				"department": "IT",
				"title":"Senior Java Developer"
			}
		],
		"birthday": Date("08/01/1980"),
		"note": "",
		"photos": [
			{
				"value": "https://pbs.twimg.com/profile_images/570169987914924032/pRisI2wr_400x400.jpeg"
			}
		],
		"categories": null,
		"urls": null
	}	

More complex version can be found in a provided tutorial. Leave me a message if you have more question or if you think something is missing.