Validation on Total from Related Item Control

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Jon
Posts: 4
Joined: Sun Jun 26, 2016

27 Jun 2016

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

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

28 Jun 2016

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).

Jon
Posts: 4
Joined: Sun Jun 26, 2016

28 Jun 2016

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

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

28 Jun 2016

Yes, right! I have not tested my code.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests