Can Widget script edit entery field?

57 views
Skip to first unread message

karam mohammed 1

unread,
Aug 7, 2025, 12:05:13 PMAug 7
to mementodatabase
Hello every one, I'm trying to render a widget that lists patients with overdue appointments (more than 30 days ago) where Done is unchecked, and displays a button for each patient.

The button should:

1. Set the "Appointment" field of that entry to today's date.


2. Open the entry.


3. Refresh the widget view.



However, the button does nothing when clicked — no field is updated, no message is shown, and no errors appear.



Here is Script I used:.

(function renderWidget() {
    var patientField = "Patient";         // Text or link field
    var appointmentField = "Appointment"; // Date field
    var doneField = "Done";               // Boolean field
    var allItems = lib().entries();
    var layout = [];

    var today = moment().format('YYYY-MM-DD');
    var now = moment();

    for (var i = 0; i < allItems.length; i++) {
        var item = allItems[i];

        // Skip if Done is checked
        if (item.field(doneField) === true) continue;

        var patientName = item.field(patientField) || "❓ Unknown";
        var appointmentDate = item.field(appointmentField);

        if (!appointmentDate) continue;

        var daysAgo = now.diff(moment(appointmentDate), 'days');
        if (daysAgo > 30) {
            layout.push(
                ui()
                    .button("👤 " + patientName + " — " + daysAgo + " days ago")
                    .action((function(entryCopy, name) {
                        return function() {
                            entryCopy.set(appointmentField, today);
                            entryCopy.save();
                            message("✅ Updated appointment for: " + name);
                            return renderWidget();
                        };
                    })(item, patientName))
            );
        }
    }

    if (layout.length === 0) {
        layout.push(ui().text("✅ All relevant patients have recent appointments."));
    }

    return ui().layout(layout);
})();




Screenshot_20250807_190144_Memento Database.jpg

Mmm

unread,
Aug 7, 2025, 5:06:21 PMAug 7
to mementodatabase
(function renderWidget() {
    var patientField = "Patient";         // Text or link field
    var appointmentField = "Appointment"; // Date field
    var doneField = "Done";               // Boolean field
    var allItems = lib().entries();
    var layout = [];

    var now = moment().startOf("d");


    for (var i = 0; i < allItems.length; i++) {
        var item = allItems[i];

        // Skip if Done is checked
        if (item.field(doneField) === true) continue;

        var patientName = item.field(patientField) || "❓ Unknown";
        var appointmentDate = item.field(appointmentField);

        if (!appointmentDate) continue;

        var  appointmentDateStart =  moment(appointmentDate).startOf("d");
        var daysAgo = now.diff(appointmentDateStart , 'days');
        if (daysAgo > 30) {
            layout.push(
                ui()
                    .button("👤 " + patientName + " — " + daysAgo + " days ago")
                    .action((function(entryCopy, name) {
                        return function() {
                            entryCopy.set(appointmentField, Date.now());
                            return true;

                        };

                        message("✅ Updated appointment for: " + name);
                        renderWidget();
                       
                    })(item, patientName))
            );
        }
    }

    if (layout.length === 0) {
        layout.push(ui().text("✅ All relevant patients have recent appointments."));
    }

    return ui().layout(layout);
})();

К сожалению, как открыть запись - не знаю.
entryCopy.show(); - из виджета не работает.

четверг, 7 августа 2025 г. в 19:05:13 UTC+3, kara...@gmail.com:

karam mohammed 1

unread,
Aug 7, 2025, 6:26:33 PMAug 7
to mementodatabase
Thanks Mmm. It worked perfect regarding edit date field. Unfortunately, It didn't  open the entry. I hope the bottom can trigger another action script that can do this.
Thank you very much
Reply all
Reply to author
Forward
0 new messages