Count and sum fields from related items table

rss

Posted by Jaydius - Nov 16 ’16 at 04:43

Is it possible to count the number of records in a related items table, and then use the total value to populate a form field e.g. 'Total Related Items'?

Also, is it possible to sum a number field from all related items and also use that totalised value to populate a form field, such as 'Total Hours'?

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 20 days
    #1 by Dmitry Kozlov Nov 17 ’16 at 04:48

    Here is how you can get data from the related items control:

    fd.relatedItems(0).data('ctx').ListData.Row[0].Title
    

    where the first index is 0-based index of the Related Items control in a page, the second – index of the row in the Related Items control, and Title is the internal name of a field.

    Just sum values from the required column and put it into a field.

  • joetel8
    Member
    Member for: 2 years 10 months 14 days
    #2 by joetel8 Mar 19 ’17 at 07:32

    Hello,

    I noticed the person who posted this question did not respond to your solution.  I am needing more information on this solution.  When you say.. that the "Title" is the internal name, are you refering to the internal name of the field in the related item table?

     

    Joe

  • joetel8
    Member
    Member for: 2 years 10 months 14 days
    #3 by joetel8 Mar 19 ’17 at 07:42

    [#2]:  Follow up question.  I wanted to place a border around the column header of related item list.

    I was able to use css to place a border around the body of the table by applying this:

    .ms-listviewtable > tbody > tr > td { border: 1px black solid;}

    but I am not able to do the same to the column header.

    Thank you in advance.

    Joe

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 20 days
    #4 by Dmitry Kozlov Mar 20 ’17 at 06:42

    [#2]: Yes, the internal name of a field in the related list.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 20 days
    #5 by Dmitry Kozlov Mar 20 ’17 at 06:46

    [#3]: Please, use the CSS:

    .ms-listviewtable > thead > tr > th { border: 1px black solid;}

    Please, ask future questions in our new forum:

    http://spform.com/forum

Displaying 1 to 5 of 5 messages