Embedded object format

112 views
Skip to first unread message

Graham Wood

unread,
May 28, 2025, 5:56:20 AM5/28/25
to mementodatabase
I have a school database where I have a list of new devices being installed.
The attributes under my embedded object is
Model
Mac Address
Location

When my script emails the details they all run together like this

Install Date: 30 May 25
Devices:
[{Model=iRADV DX C5860, Mac Address=23F8C978BDE8, Location=Admin}, {Model=iR1643P, Mac Address=56C9C5F28DB, Location=Office}]

I would like it to format like this

Install Date:          30 May 25
Devices:
Model=iRADV DX C5860
Mac Address=23F8C978BDE8
Location=Admin
-----------------------------
Model=iR1643P
Mac Address=56C9C5F28DB
Location=Office

This is my current email script. How do I modify it to achieve what I want it to look like.

let e = entry();
let line = "\n" + "-".repeat(56);
let line1 = "\n" + "-".repeat(32);

let txt = e.field("message");
txt += "\n";
txt += "\nInstall Date:" + " "
 + moment(e.field("install date")).format('DD MMM YY');
txt += "\nDevices:" 
txt += "\n"+e.field("devices");
txt += "\n";

AndroidMessages.email(e.field("IT email"), e.field("school")+" Printer Installation", txt);

Mmm

unread,
May 28, 2025, 3:10:57 PM5/28/25
to mementodatabase
Являются ли атрибуты  "Model", "Mac Address", "Location" обязательными к заполнению?

среда, 28 мая 2025 г. в 12:56:20 UTC+3, grahamsc...@gmail.com:

Graham Wood

unread,
May 28, 2025, 5:51:49 PM5/28/25
to mementodatabase
Hi Mmm
Yes they are mandatory. We as technicians gather this info for the IT department and email it on.
Each school can have different number of devices.
Eg 1 school may have 5 new devices going it and the next might have 2 and the next could have 7
If making the attributes mandatory or not has any bearing on the scripting it's no big issue as we know it has to be filled in for each device anyway.
So whatever way works we would go with.

Mmm

unread,
May 28, 2025, 6:06:04 PM5/28/25
to mementodatabase
Есть вариант, который работает на мобильной версии, но не работает на настольной версии.
К сожалению, не осилил...

четверг, 29 мая 2025 г. в 00:51:49 UTC+3, grahamsc...@gmail.com:

Mmm

unread,
May 28, 2025, 6:17:02 PM5/28/25
to mementodatabase
//Формирование списка устройств
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:

Graham Wood

unread,
May 29, 2025, 1:56:12 AM5/29/25
to mementodatabase
thanks Mmm works exactly as I wanted
Reply all
Reply to author
Forward
0 new messages