Embeded object null

117 views
Skip to first unread message

karam mohammed 1

unread,
Jul 22, 2025, 6:23:32 AM7/22/25
to mementodatabase
Hello everyone one . I use this action script to delete selected elements of embeded object fields , but I always delete all even I select only one . Can it be repaired. .
Thanks in advance


// This is an 'Entry' action script to delete selected payments
// from the 'hesab' embedded object field.

(function () {
    try {
        var e = entry();

        // --- Configuration ---
        var hesabFieldName = "hesab";
        var dateAttribute = "date";
        var paidAttribute = "paid";
        // -------------------

        var payments = e.field(hesabFieldName);

        if (!payments || payments.length === 0) {
            message("No payments found to delete.");
            exit();
        }

        var uiElements = [];
        uiElements.push(ui().text("Select payments to delete:").font({ style: 'bold' }));

        // Create a checkbox for each payment.
        for (var i = 0; i < payments.length; i++) {
            var payment = payments[i];
            var paymentDate = moment(payment[dateAttribute]).format("YYYY-MM-DD");
            var paymentAmount = payment[paidAttribute];
            var label = paymentDate + " - " + paymentAmount;
            
            // The 'tag' is used to identify which checkbox corresponds to which payment.
            uiElements.push(
                ui().checkbox(label, false).tag('payment_' + i)
            );
        }

        // --- Main Dialog to Select Payments ---
        dialog()
            .title("Delete Payments")
            .view(ui().layout(uiElements))
            .positiveButton("Delete Selected", function() {
                
                var newPaymentsArray = [];
                var deletedCount = 0;
                
                // Loop through the original payments to see which ones were selected.
                for (var i = 0; i < payments.length; i++) {
                    var checkbox = ui().findByTag('payment_' + i);
                    if (checkbox && !checkbox.checked) {
                        // If the box is NOT checked, keep the payment.
                        newPaymentsArray.push(payments[i]);
                    } else {
                        deletedCount++;
                    }
                }
                
                if (deletedCount === 0) {
                    message("No payments were selected for deletion.");
                    return false; // Keep the dialog open.
                }

                // --- Confirmation Dialog ---
                dialog()
                    .title("Confirm Deletion")
                    .text("Are you sure you want to delete " + deletedCount + " payment(s)? This cannot be undone.")
                    .positiveButton("Yes, Delete", function() {
                        // Overwrite the 'hesab' field with the new array that excludes the deleted items.
                        e.set(hesabFieldName, newPaymentsArray);
                        message(deletedCount + " payment(s) deleted. Please refresh your summary tables.");
                        return true; // Closes the confirmation dialog.
                    })
                    .negativeButton("Cancel", function() {})
                    .show();

                return true; // Closes the main selection dialog.
            })
            .negativeButton("Cancel", function() {})
            .show();

    } catch (err) {
        message("An error occurred: " + err.message);
    }
})();

David Gilmore

unread,
Jul 22, 2025, 11:56:44 AM7/22/25
to mementodatabase
WIthout me entering the code and testing it locally:

Remember that Memento Dialog's are a fire and forget operation, in other words the trigger/function will continue executing and finish executing while that Dialog box is still being shown on the screen.

When I have operations like this, I use a "bulk Action" trigger, and let the user select the records (using a long press):

var entries = selectedEntries();
for (let e of entries) {
  e.trash();
}

Or you can also scan the whole library and check to see if the entry is a candiate for deletion:

var entries = lib().entries();
for (let e of entries) {
  if (<condition check to see if this should be deleted>) {
    e.trash()
  }
}

Hope this helps.

Mmm

unread,
Jul 22, 2025, 1:09:05 PM7/22/25
to mementodatabase
Автору нужно удалить не записи библиотеки, а отдельные элементы в поле встроенный объект конкретной записи.

Попробуйте воспользоваться конструктором объектов:

function Element(ob) {
    this.date = ob.date;
    this.paid = ob.paid;
}

замените строку:
// If the box is NOT checked, keep the payment.
newPaymentsArray.push(payments[i]);

на: 
// If the box is NOT checked, keep the payment.
newPaymentsArray.push(new Element(payments[i]));


У меня нет объяснений, но если вставить в поле встроенный объект первоначальный массив - это тоже не работает.
var e = entry();
var hesabFieldName = "hesab";
var payments = e.field(hesabFieldName);
e.set(hesabFieldName, payments);// результат пустое поле

Поэтому всегда пользуюсь конструктором объектов.
Но есть еще проблема - конструктор объектов не работает в настольной версии.

Вероятно нужно обратиться к разработчику для пояснения, как правильно работать с элементами поля встроенный объект.

вторник, 22 июля 2025 г. в 18:56:44 UTC+3, aa6...@gmail.com:

karam mohammed 1

unread,
Jul 22, 2025, 5:01:05 PM7/22/25
to mementodatabase
Thank  aa6 for your interest .
Thanks Mmm for your answer . It worked with me . Smart solution as usual.

Mmm

unread,
Jul 23, 2025, 8:20:32 AM7/23/25
to mementodatabase
Иногда необходимо изменить интервал по высоте между элементами формы.
Это можно сделать путем добавления пустого ui().text().
Интервал регулируется высотой шрифта.

Пример на скриншотах:
1. Интервал отсутствует:

        var uiElements = [];
        uiElements.push(ui().text("Select payments to delete:").font({ style: 'bold' }));   
        // Create a checkbox for each payment.
        ...

2. Интервал (5 пт):

        var uiElements = [];
        uiElements.push(ui().text("Select payments to delete:").font({ style: 'bold' }));
        uiElements.push(ui().text("").font({ size: 5 }));
        // Create a checkbox for each payment.
        ...

3. Интервал (10 пт):

        var uiElements = [];
        uiElements.push(ui().text("Select payments to delete:").font({ style: 'bold' }));
        uiElements.push(ui().text("").font({ size: 10 }));
        // Create a checkbox for each payment.
        ...

среда, 23 июля 2025 г. в 00:01:05 UTC+3, kara...@gmail.com:
IC__23072025.jpg

karam mohammed 1

unread,
Jul 24, 2025, 6:00:35 PM7/24/25
to mementodatabase
Great. Thanks Mmm again and again
Reply all
Reply to author
Forward
0 new messages