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);
}
}