Page 1 of 1

Validation on Total from Related Item Control

Posted: 27 Jun 2016
by Jon
Hi,

I have set up a Parent Child relationship using the Related Item Control. This works great for new items and editing. On the Child list, I have an hours column. I need to verfiy that the sum of the hours from the child items does not exceed 40 hours. How can I perform a running total and generate an error if sum of hours > 40? I am using the inline edit mode.

Thanks,

Jon

Re: Validation on Total from Related Item Control

Posted: 28 Jun 2016
by Dmitry Kozlov
Hi Jon,

If you're using Forms Designer 3.0.8, you can use the following code:

Code: Select all

fd.onsubmit(function() {
    var total = 0;
    var rows = fd.relatedItems(0).data('ctx').ListData;
    for (var i = 0; i < rows.length; i++) {
        total += rows[i].Hours;
    }

    if (total > 40) {
        alert('Total amount of hours must be less than 40');
        return false;
    }

    return true;
});
Replace 'Hours' with the internal name of the 'hours' column. If you have multiple Related Items controls in your form, put the appropriate 0-based index into fd.relatedItems(index).

Re: Validation on Total from Related Item Control

Posted: 28 Jun 2016
by Jon
Hi Dmitry,

Thanks for the quick reply! This works great (I did need to add Row to the end of this statement).

var rows = fd.relatedItems(0).data('ctx').ListData.Row

Jon

Re: Validation on Total from Related Item Control

Posted: 28 Jun 2016
by Dmitry Kozlov
Yes, right! I have not tested my code.