//Формирование списка устройств
const objToText = items => {
let result = [];
let names = ["Model", "Mac Address", "Location"];
let devices = items.map(a => new Device(a));
for (let item of devices) {
let element = [];
for (let name of names) {
if (item.hasOwnProperty(name)) {
element.push(name + ": " + item[name]);
}
}
if (element.length > 0) {
result.push(element.join("\n"))
}
}
if (result.length > 0) {
return result.join(line(32));
} else {
return "No information";
}
};
//Строка-разделитель любой длины
const line = nn => {
return "\n" + "-".repeat(nn) + "\n";
};
let e = entry();
let txt = e.field("message");
txt += "\n\nInstall Date: " + moment(e.field("install date")).format('DD MMM YY');
txt += "\nDevices:\n";
txt += objToText(e.field("devices"));
txt += "\n";
AndroidMessages.email(e.field("IT email"), e.field("school")+" Printer Installation", txt);
//Конструктор объектов
function Device(ob) {
this["Model"] = ob["Model"];
this["Mac Address"] = ob["Mac Address"];
this["Location"] = ob["Location"];
}
Полную работоспособность не проверял.
четверг, 29 мая 2025 г. в 01:06:04 UTC+3, Mmm: