Creating a Dynamic Schedule
Subscription Tier Required
This feature requires the Premier subscription tier or higher.
While Simple Schedules may work in some cases, it is common for required quality checks to change based on:
- The current Part being produced.
- A third party system, like an ERP.
- Whether any Real-Time Failures were detected.
In this guide, you will create a Schedule which runs a set of checks at the beginning of every day. Based on the Part selected during the Start of Day Inspection, a different set of checks will be required throughout the day at different frequencies. This will be accomplished through the use of a Recurring Schedule which will be triggered at the beginning of every day, and a Scripted Schedule which will be triggered manually after the completion of the Start of Day checks.
The Traceability set on the initial Start of Day Inspection will be carried through to every check completed after, meaning they only need to be filled in once at the beginning of the day.
If you are not familiar with Accountability Data in GS, see the Core Concepts.
Prerequisites
This guide assumes that you have:
- At least two Parts with at least one Characteristic each.
- Two Traceability fields: Line and Operator.
This guide will use the Parts 24 oz Spring Water and 24 oz Seltzer. The 24 oz Spring Water requires that its Weight and Total Dissolved Solids are checked every 60 minutes for 7 hours. The 24 oz Seltzer requires that its Weight, pH, and Dissolved C02 are checked every 30 minutes for 7.5 hours. These checks exist as Characteristics on these Parts.
If you do not have these prerequisites, first complete the guides on Collecting SPC Data and Collecting Traceability.
Create the Start of Day Inspection
Begin by creating the Inspection which will run at the start of every day, and will be used to trigger additional Schedules based on the information submitted:
- Navigate to the Inspection list.
- Press the Add button.

- Fill in the Name field with Start of Day Checks.
- Press the Save button.

- Add a Part Test.
- Add a Traceability Test and select Line.
- Add another Traceability Test and select Operator.
- Add a Task Test and change the label to "I have cleaned and organized my work space.".

- Select the Save action.
- Navigate to the Inspection List and use the More Actions menu to Edit the Inspection settings.

- Set the Published Revision to Revision 1.

You will come back to this Inspection to set up the Schedule trigger in a later step.
Create the Checks Inspections
Next, create the Inspections that will run periodically:
- Navigate to the Inspection list.
- Press the Add button.
- Fill in the Name field with Spring Water Checks.
- Press the Save button.
- In the Inspection Data Area, add the following tests:
- A disabled Traceability Test with the Traceability set to Line.
- A disabled Traceability Test with the Traceability set to Operator.
- In the first Sub-Inspection, add SPC Tests with the following Characteristics from the 24 oz Spring Water Part:
- Weight.
- Total Dissolved Solids.
- Select the Save action.
- Navigate to the Inspection List and use the More Actions menu to Edit the Inspection settings.
- Set the Published Revision to Revision 1.
- Take note of the ID of this Inspection for later.

Repeat these steps to create an Inspection named Seltzer Checks, using the Weight, pH, and Dissolved C02 Characteristics. Also take note of this ID.
After creating the Inspections, you should have a list that looks similar to this:
Exercise
Try modifying the Inspection to use Dynamic Tags to reuse a single Inspection instead of creating multiple.
Create the Start of Day Schedule
The Start of Day checks will be set up as a Recurring Schedule which will start every morning at 8:00 AM. However, unlike the Simple Schedule, the Start of Day checks will only be performed once:
- Navigate to the Schedules list.
- Press the Add button.

- Fill in the Name field with Start of Day Schedule.

- If you have mulitiple Locations in your account, select a Location.
- Modify the other settings as desired. See the Schedule Reference for more information about each setting.
- Leave the Trigger Type as Recurring.
- Change the Schedule to Every Weekday.
- Change the Start Date to 8:00 AM today.
- Change End After Occurrences to 1.

Before saving, link an Inspection to the Schedule. When a Schedule is triggered, it will set up an Accountability record for each linked Inspection. These linked Inspections will automatically have Traceability, Parts, and Processes preset based on your choices on the Schedule.
- Click the Add button.

- Set the Inspection to Start of Day Checks.
- Leave the Process as the default.
- If you have created multiple Processes, you will need to select a process.
- Leave the Part empty.
- Leave the Traceability empty.
- Save the linked Inspection.

Information
For the sake of this guide, the Start of Day checks does not have any Traceability set. This results in this Schedule applying to all Users. See the Simple Schedule Guide for targeting the Schedule to specific Users.
Finally, save the Schedule.
Create the Periodic Checks Schedule
Next, create another Schedule that will be triggered using scripting. Unlike a Recurring Schedule, a Scripted Schedule must be triggered manually. Repeat the same steps as creating a Recurring Schedule, but instead change the Trigger Type to Scripted.
Give this Schedule the name Periodic Schedule.
Notice that most of the fields disappear when the Trigger Type is set to Scripted. For Scripted Schedules, the linked Inspections and frequency of recurrence are defined in the triggering script.
Add Periodic Check Lookup
We need some way to check what Inspection should be run for different Parts and how frequently they should be run. This guide will use a Library Script with hardcoded values for each Part. However, this could be pulled from a third-party system (like an ERP), read from a file inside of GS, or pulled from a local database.
To create the Library Script:
- Navigate to the list of Library Scripts.
- Press the Add button.

- Fill in the Name with Retrieve Schedules.
- Press the Save button.

-
Fill in the Library Script.
/** * @typedef {Object} InspectionRun * @property {number} inspectionId * @property {number} recurrences * @property {number} interval * @property {Date} startDate */ /** * Retrieves the Inspection to run and how frequently they should be run. * @param {string} partName * @returns {InspectionRun} */ function getScheduleForPart(partName) { const nextRun = new Date(); // Floor the time to the nearest minute nextRun.setSeconds(0); nextRun.setMilliseconds(0); if (partName.includes('Spring Water')) { // Next run should be at 9:00 AM, and repeat every 60 minutes for 7 times. nextRun.setHours(9); nextRun.setMinutes(0); return { interval: 60, recurrences: 7, startDate: nextRun, inspectionId: {SPRING WATER INSPECTION ID}, }; } else if (partName.includes('Seltzer')) { // Next run should be 8:30 AM, and repeat every 30 minutes for 15 times. nextRun.setHours(8); nextRun.setMinutes(30); return { interval: 30, recurrences: 15, startDate: nextRun, inspectionId: {SELTZER INSPECTION ID}, }; } }Replace the
{SPRING WATER INSPECTION ID}and the{SELTZER INSPECTION ID}with the IDs of the Inspections you recorded earlier.
Exercise
Try modifying the Library Script to instead read an Excel file stored in GS. See the guide on Using Library Scripts for an example of reading an Excel file.
Trigger the Periodic Checks
Next, you will add a script that will trigger the appropriate schedule when the Start of Day checks have been completed. Navigate back to the Start of Day Checks Inspection and edit the revision:
- Navigate to the Inspection list.
- Press the Edit Revision button.

- Select the Scripts action.

- Add your Library Script.
- Add a new Inspection Script.

- Name the Inspection Script Trigger Schedule.
At this point, you should see the Code Editor. Fill in the Name field with the value Trigger Schedule, and add the following to the script window:
const subInspection = gsApi.inspection.subInspection('subi 1');
subInspection.onAfterEnd(async (e) => {
});
This binds a function to an event that will run when the Sub-Inspection has ended. The default Sub-Inspection Script ID is subi 1. When the Sub-Inspection ends, we want to trigger the appropriate checks based on the selected Part. First, begin by checking to make sure that the Sub-Inspection wasn't cancelled:
const subInspection = gsApi.inspection.subInspection('subi 1');
subInspection.onAfterEnd(async (e) => {
if (e.data.actionType !== 'submit' || !e.data.dataSet) {
return;
}
});
Next, get some information used to trigger the Inspection. This includes the ID of the Scripted Schedule created above, the Part submitted with the data, and the Schedule from the Library Script created earlier:
const subInspection = gsApi.inspection.subInspection('subi 1');
subInspection.onAfterEnd(async (e) => {
...
const scheduleId = await gsApi.entity.getScheduleIdByName('Periodic Schedule');
const part = await gsApi.entity.getPartById(/** @type {number} **/(e.data.dataSet.partId));
const scheduleData = getScheduleForPart(part.name);
});
Finally, call the function to trigger the Schedule. This will create new Accountability Data Records which will show up in the My Schedules page.
const subInspection = gsApi.inspection.subInspection('subi 1');
subInspection.onAfterEnd(async (e) => {
...
await gsApi.schedules.triggerInspectionSchedule({
contexts: [{
inspectionId: scheduleData.inspectionId,
processId: /** @type {number} **/(e.data.dataSet.processStandardId),
partId: e.data.dataSet.partId,
traceability: e.data.dataSet.traceability
}],
interval: scheduleData.interval,
recurrences: scheduleData.recurrences,
startTime: scheduleData.startDate
}, scheduleId);
});
Update the Current Schedule
Each Scheduled Inspection which appears on the My Schedules page is actually an Accountability Data Record. Like other types of data, Accountability data is stored with Traceability. When an Accountability Record is created from a Recurring Schedule, it inherits the Traceability from the linked Inspection that was used to create it. When the Accountability Record is marked as complete (which occurs when an Inspection is Completed), the Traceability is updated to the Traceability which is set on the Inspection.
The Accountability Data created by the Start of Day Schedule initially has no Traceability on it, and there is no Traceability stored directly on the Inspection—it only exists on the Sub-Inspection. There are several ways that this could be remedied:
- Update the Part and Traceability on the Inspection when the Sub-Inspection is submitted.
- Move any Part, Process, or Traceability tests to the Inspection Data area.
- Update the Accountability Data Record directly when the Sub-Inspection is submitted.
In this guide, we will do the third option. At the bottom of your script, update the Accountability Record that was used to trigger this Inspection to include the Traceability:
const subInspection = gsApi.inspection.subInspection('subi 1');
subInspection.onAfterEnd(async (e) => {
...
const properties = await gsApi.inspection.getProperties();
if (properties.accountabilityId) {
await gsApi.schedules.updateScheduledInspection({
traceability: e.data.dataSet.traceability
}, properties.accountabilityId);
}
});
Save the Sub-Inspection.
Test the Schedule
For the purpose of this guide, you may test the Schedule by manually running the Start of Day Checks Inspection:
- Navigate to the Inspection List.
- Run the Start of Day Checks Inspection.
- Complete the Inspection.
- Navigate to the My Schedules page.

- When possible, Run one of the Scheduled Inspections.
Notice that the Traceability is the same as the selection made during the Start of Day Checks.
View the Data
Follow the instructions in the Simple Schedule and create an Accountability Data Table.
Final Code
const subInspection = gsApi.inspection.subInspection('subi 1');
subInspection.onAfterEnd(async (e) => {
if (e.data.actionType !== 'submit' || !e.data.dataSet) {
return;
}
const scheduleId = await gsApi.entity.getScheduleIdByName('Periodic Schedule');
const part = await gsApi.entity.getPartById(/** @type {number} **/(e.data.dataSet.partId));
const scheduleData = getScheduleForPart(part.name);
const traceability = e.data.dataSet.traceability
.filter(x => x.value);
await gsApi.schedules.triggerInspectionSchedule({
contexts: [{
inspectionId: scheduleData.inspectionId,
processId: /** @type {number} **/(e.data.dataSet.processStandardId),
partId: e.data.dataSet.partId,
traceability: traceability
}],
interval: scheduleData.interval,
recurrences: scheduleData.recurrences,
startTime: scheduleData.startDate
}, scheduleId);
const properties = await gsApi.inspection.getProperties();
if (properties.accountabilityId) {
await gsApi.schedules.updateScheduledInspection({
traceability: traceability
}, properties.accountabilityId);
}
});


