function toTitleCase(word) {
if (word === null) {
return word;
}
return word.split(' ')
.map(w => w.charAt(0).toUpperCase() + w.substring(1).toLowerCase())
.join(' ');
}
contact = bx24.callMethod('crm.contact.get', {id: contactId});
let newName = toTitleCase(contact.NAME);
let newLastName = toTitleCase(contact.LAST_NAME);
let newMiddleName = toTitleCase(contact.SECOND_NAME);
let updated;
if (contact.NAME !== newName
|| contact.LAST_NAME !== newLastName
|| contact.SECOND_NAME !== newMiddleName) {
console.log('Обновляем контакт');
bx24.callMethod('crm.contact.update', {
id: contactId,
fields: {
NAME: newName,
LAST_NAME: newLastName,
SECOND_NAME: newMiddleName
}
});
updated = true;
} else {
console.log('Контакт не требует обновления');
updated = false;
}
return {"isUpdated": updated};