Commit 3b8517b1 authored by Irina Oleynik's avatar Irina Oleynik

Отправка почтового сообщения

parent 1ea188bd
var result = true;
var message = "ok";
try {
let THEME_CMP_ID = 'itsm_form_settings_external_provider_get_incident_theme';
let SUBJECT_CMP_ID = 'itsm_form_settings_external_provider_get_incident_text';
let SETTINGS = API.httpGetMethod('rest/api/registry/data_ext?registryCode=itsm_registry_settings&fields=' + THEME_CMP_ID + '&fields=' + SUBJECT_CMP_ID);
if(SETTINGS.recordsCount == 0) throw new Error('Не найдены настройки');
let mailTheme = SETTINGS.result[0].fieldValue[THEME_CMP_ID];
let mailSubject = SETTINGS.result[0].fieldValue[SUBJECT_CMP_ID];
if(!mailTheme && !mailSubject) throw new Error('Не найдены настройки для формирования сообщения');
let currentFormData = API.getFormData(dataUUID);
let supplier_email = UTILS.getValue(currentFormData, 'itsm_form_incident_supplier_email');
UTILS.getParams(mailTheme).forEach(function(id) {
mailTheme = mailTheme.replace('${'+id+'}', UTILS.getValue(currentFormData, id).value || '');
});
UTILS.getParams(mailSubject).forEach(function(id) {
mailSubject = mailSubject.replace('${'+id+'}', UTILS.getValue(currentFormData, id).value || '');
});
// отправка письма
if(supplier_email && supplier_email.value && supplier_email.value != '') {
log.info('|||||||||| SUPPLIER EMAIL: ' + supplier_email.value);
log.info('|||||||||| THEME: ' + mailTheme);
log.info('|||||||||| SUBJECT: ' + mailSubject);
let sendResult = API.sendNotification({
header: mailTheme,
message: mailSubject,
emails: [supplier_email.value]
});
if(sendResult == 200) {
log.info('Уведомление успешно отправлено');
message = 'Уведомление успешно отправлено';
} else {
throw new Error('Произошла ошибка отправки уведомления');
}
} else {
throw new Error('Не найден email получателя');
}
} catch (err) {
log.error(err.message);
message = err.message;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment