# Last 7 days script

**URL:** <https://the.fmsoup.org/t/last-7-days-script/3096>\
**Category:** Questions\
**Tags:** scripting\
**Created:** [September 16, 2022, 10:04pm UTC](https://the.fmsoup.org/t/last-7-days-script/3096 "2022-09-16T22:04:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ClarisUSER](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@ClarisUSER](https://the.fmsoup.org/u/ClarisUSER)\
**Post date:** [September 16, 2022, 10:04pm UTC](https://the.fmsoup.org/t/last-7-days-script/3096/1 "2022-09-16T22:04:33Z")

</div>

I want to create a button.

I have a field that i want to see the total hours that student has spent flying.

Each training session will accumulate hours flown.  
I want to clock a button to show the total hours the student has flown..

can somebody help me out with this?

---

<div class="post-metadata">

**Author:** ![bdbd](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bdbd/32/620_2.png) [@bdbd](https://the.fmsoup.org/u/bdbd)\
**Post date:** [September 16, 2022, 11:23pm UTC](https://the.fmsoup.org/t/last-7-days-script/3096/2 "2022-09-16T23:23:28Z")

</div>

Welcome to The Soup @ClarisUSER. I hope The Soup becomes a valuable FileMaker resource for you.

I assume you operate a flight school. I also assume your solution has a student table and a training session table. You can create a field in the student table that sums the hours flown field of the training session table.

There is no need for a button, unless I misunderstood your request.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![xochi](https://avatars.discourse-cdn.com/v4/letter/x/0ea827/32.png) [@xochi](https://the.fmsoup.org/u/xochi)\
**Post date:** [September 16, 2022, 11:24pm UTC](https://the.fmsoup.org/t/last-7-days-script/3096/3 "2022-09-16T23:24:50Z")

</div>

The normal "FileMaker" way of doing this would not involve scripting or a button at all.

You would have two Tables, a **users** table and a **flights** table.  
The **flights** table would be a list of flights (with some sort of field that indicated the # of training hours, e.g. "FlightHours")

The two tables would be related by an ID field (probably Student ID).

You then create a Calculated field in the **users** table which has a formula something like this:

TotalFlightHours = Sum(Flights::FlightHours)

No need for a button or script.

[Edit to add: seems like bdbd and I came up with basically the same solution. The FileMaker Force is strong here]

[Edit 2: your title is "last 7 days". If you wanted to limit this calculation to only flights in the past week, you could do this a few ways. One way would be to create a relationship between the two tables that uses the \< and \> relationship operators, e.g. a relationship where:

- Student::ID = Flights::StudentID
- today \>= Flights::dateOfFLight
- weekAgo \< Flights::dateOfFlight

where Today and WeekAgo are calculated fields.

---

<div class="post-metadata">

**Author:** ![ClarisUSER](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@ClarisUSER](https://the.fmsoup.org/u/ClarisUSER)\
**Post date:** [September 17, 2022, 2:11am UTC](https://the.fmsoup.org/t/last-7-days-script/3096/4 "2022-09-17T02:11:41Z")

</div>

The customer is specifically asking for a script/button so the system doesn't think or slow down ... reloading when clicking between portals etc

---

<div class="post-metadata">

**Author:** ![ClarisUSER](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@ClarisUSER](https://the.fmsoup.org/u/ClarisUSER)\
**Post date:** [September 17, 2022, 3:45am UTC](https://the.fmsoup.org/t/last-7-days-script/3096/5 "2022-09-17T03:45:10Z")

</div>

I forgot to add i want to have 14 days 30 days 90 days and 180 days.... i have the fields in the tables but to be updated once i press the button

---

<div class="post-metadata">

**Author:** ![bdbd](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bdbd/32/620_2.png) [@bdbd](https://the.fmsoup.org/u/bdbd)\
**Post date:** [September 17, 2022, 4:55am UTC](https://the.fmsoup.org/t/last-7-days-script/3096/6 "2022-09-17T04:55:01Z")

</div>

Then it's a classic case of running a bunch of finds in the training session table to compute the numbers. If the fields that will display the results are not in the same table, you will need to store the results temporarily in variables or globals fields.
