Script for moving middle names to family names in all contacts

Hi,

In Spain it is common that people preserve family names from both their parents. So I had this issue where I would have contacts with one of their family names written in the middle name parameter. This was probably the result of having used different Contact apps along the years. In order to move those middle names to the family name parameter, I wrote the following script. I hope it is helpful to you!

let containers = await ContactsContainer.all();
let contacts = await Contact.all(containers);
contacts.forEach(await rename);
Contact.persistChanges();

var lastname = '';

async function rename(contact) {
	if(contact.middleName.length != 0){
		lastname = contact.familyName;
		contact.familyName = contact.middleName + ' ' + lastname;
		contact.middleName = ''
		log(contact.familyName);
		Contact.update(contact);
	}
}
5 Likes

Cool. Thanks for sharing! :blush:

1 Like

2 posts were split to a new topic: Edit Contact Field