Error while running script

i am getting this error while running a timer script, this works in the script console but in the timer

'com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 1, in ImportError: No module named project'

'at org.python.core.Py.ImportError(Py.java:327)'

'at org.python.core.imp.import_first(imp.java:1232)'

'at org.python.core.imp.import_module_level(imp.java:1363)'

'at org.python.core.imp.importName(imp.java:1544)'

'at org.python.core.ImportFunction.call(builtin.java:1285)'

'at org.python.core.PyObject.call(PyObject.java:433)'

'at org.python.core.builtin.import(builtin.java:1232)'

'at org.python.core.imp.importFromAs(imp.java:1636)'

at org.python.core.imp.importFrom(imp.java:1611)

at org.python.pycode._pyx3.f$0(:50)

at org.python.pycode._pyx3.call_function()

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1703)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:804)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:859)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:752)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:840)

at com.inductiveautomation.ignition.common.script.TimerScriptTask.run(TimerScriptTask.java:92)

at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.runAndReset(Unknown Source)

at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown Source)

Caused by: org.python.core.PyException: ImportError: No module named project

script for timer.txt (2.9 KB)

Welcome to the forum Thomas.

Please see Wiki - how to post code on this forum - General Discussion - Inductive Automation Forum

This will help others help you.

# Database connection name
db_connection = "SQL_Server"

def insert_suite_data(suite_name, tag_paths):
    # Read tag values
    tag_values = system.tag.readBlocking(tag_paths)
    data_values = [value.value if value.quality.isGood() else 0 for value in tag_values]

    # Debugging: Print extracted data values
    print("Data Values for Suite: " + suite_name)
    print("Extracted Data Values:", data_values)

    # Define SQL query
    query = """
        INSERT INTO [dbo].[shift_production_data] 
        ([shift_end_time], [suite name], [cw reject], [crt minutes], [crt hours], [cdt hours], [cdt minutes], 
        [sdt hours], [sdt minutes], [srt hours], [srt minutes], [Production Hundreds], [Production Thousands])
        VALUES (CURRENT_TIMESTAMP, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    """

    # Parameters
    parameters = [suite_name] + data_values

    # Debugging: Print query and parameters
    print("SQL Query:", query)
    print("SQL Parameters:", parameters)

    # Execute the query
    try:
        system.db.runPrepUpdate(query, parameters, db_connection)
        print("Data successfully inserted for Suite: " + suite_name)
    except Exception as e:
        print("Failed to insert data for Suite: " + suite_name + ". Error: " + str(e))

# Define suites and their tag paths
suites = {
    "Suite 22": [
        "[default]Suite 22/CW Reject",
        "[default]Suite 22/crt minutes",
        "[default]Suite 22/crt hours",
        "[default]Suite 22/cdt hours",
        "[default]Suite 22/cdt minutes",
        "[default]Suite 22/sdt hours",
        "[default]Suite 22/sdt minutes",
        "[default]Suite 22/srt hours",
        "[default]Suite 22/srt minutes",
        "[default]Suite 22/Production Hundreds",
        "[default]Suite 22/Production Thousands"
    ],
    "Suite 26": [
        "[default]Suite 26/CW Reject",
        "[default]Suite 26/crt minutes",
        "[default]Suite 26/crt hours",
        "[default]Suite 26/cdt hours",
        "[default]Suite 26/cdt minutes",
        "[default]Suite 26/sdt hours",
        "[default]Suite 26/sdt minutes",
        "[default]Suite 26/srt hours",
        "[default]Suite 26/srt minutes",
        "[default]Suite 26/Production Hundreds",
        "[default]Suite 26/Production Thousands"
    ],
    "Suite 29": [
        "[default]Suite 29/CW Reject",
        "[default]Suite 29/crt minutes",
        "[default]Suite 29/crt hours",
        "[default]Suite 29/cdt hours",
        "[default]Suite 29/cdt minutes",
        "[default]Suite 29/sdt hours",
        "[default]Suite 29/sdt minutes",
        "[default]Suite 29/srt hours",
        "[default]Suite 29/srt minutes",
        "[default]Suite 29/Production Hundreds",
        "[default]Suite 29/Production Thousands"
    ]
}

# Loop through each suite and insert data
for suite_name, tag_paths in suites.items():
    insert_suite_data(suite_name, tag_paths)

Are you talking about the Gateway timer script? I am going to assume that you don't have your scripting project setup.

thanks

yes under Scripting Gateway Events

In order to use Project Scripts you have to setup one of your projects as a scripting project

Project Library | Ignition User Manual

This will allow tags and gateway scripts to see those scripting libraries you create.

This is not needed for events under "Scripting" => "Gateway Events". Those automatically use the libraries of the project within which they are defined, not the gateway scripting project.

The GSP exists for script callers that are entirely outside any project--basically, tag events and expression tag runScript().