4 Replies Latest reply on May 6, 2011 8:11 AM by philmodjunk

    Refresh Summary Field



      Refresh Summary Field



      I made a time sheet program that allows me to enter hours for employees everyweek. Employees could be working on multiple "codes" during the week and so they will have multiple hours input each week.

      I currently have a summary that adds up all of the hours used by each employee in a week. While I'm entering the hours, it doesn't automatically update the "total hours" until I click out of the portal. Is there a way I can make a script trigger or something to automatically display the total as I go? Or will I have to click out of the portal if I want to see it all add up?

      I hope thats not to confusing... thanks in advance for your help!

        • 1. Re: Refresh Summary Field

          Two options:

          Use script triggers to do a Refresh window. You can use OnObjectSave or OnObjectExit triggers to do this. You do get a bit of "window flash"--at least on windows systems when you do this.

          Replace the summary field with a calculation field in your layout's table that uses Sum (portalTable::hoursField) to compute the total. It will update smoothly without any need for scripting a window refresh.

          • 2. Re: Refresh Summary Field

            I had previously tried the refresh window script trigger on object exit and it didn't work.

            I will try to use a sum instead... but I don't understand how I make the sum field calculate the total hours of the employee for that week.

            For example on form view I have

            Employee Name: John Smith

            Date: May 6, 2011

            THen in a portal from related fields I have:

            Cost Code                Hours

            3030                        12

            1250                        5

            70                            19

            And I want the sum to show: 36 but all of the codes are created as new records in another field. I only want the sum for the selected date... can I still make a calculation for the sum instead of using the summary field? I would much prefer that but I can't figure out how to set it up!


            • 3. Re: Refresh Summary Field

              Oops I was a little quick on the trigger on the last post.

              You're right I just used the sum of the portal hour field and its keeping it up to date!

              Thanks for your help!

              • 4. Re: Refresh Summary Field

                Refresh window should work. You may need to include a commit record step or use it in place of refresh window.

                Are you using the date in a portal filter expression?

                If so, then sum won't return the correct total as aggregate functions ignore any portal filter expressions.

                There are, however, ways to structure the relationship to include a global date field that "filters" the records shown at the relationship level and then Sum and other such functions can compute values consistant with the records displayed in the portal.

                Say you have this relationship:

                Employees::EmpID = TimeWorked::EmpID

                Change it to:

                Employees::EmpID = TimeWorked::EmpID AND
                Employees::gSelectedDate = TimeWorked::DateWorked

                and you can enter/select a date in gSelectedDate to see the work done on that date and your sum function will compute the total time correctly.