# Question On Configure Scripts

**URL:** <https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090>\
**Category:** Maker\
**Tags:** perspective\
**Created:** [January 11, 2024, 1:47am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090 "2024-01-11T01:47:42Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [January 11, 2024, 1:47am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/1 "2024-01-11T01:47:42Z")

</div>

I'm sure this has been asked before but it's just not clicking for me. I'm trying to learn some basic scripting. I want to start with something simple such as when an Led display value is 1 or 2 a different Led display multiplies it by 10 or 20 and displays that value. Trying to do this when the first tag updates.

Any pointers? I saw in the documentation about custom methods but I'm not sure how to apply those correctly.

Thanks for any help

---

<div class="post-metadata">

**Author:** ![nideyijuyidong](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@nideyijuyidong](https://forum.inductiveautomation.com/u/nideyijuyidong)\
**Post date:** [January 11, 2024, 2:03am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/2 "2024-01-11T02:03:09Z")

</div>

You need a binding to trig.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/5/f5311a0f38b66afb52ed81204f43982ba50d7409.png)

---

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [January 11, 2024, 2:30am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/3 "2024-01-11T02:30:47Z")

</div>

Thanks, got me further along. Can you add to this? Such as writing the new value to a sql table? Or is that done in a different location?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 11, 2024, 2:40am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/4 "2024-01-11T02:40:57Z")

</div>

How much of the free online tutorials have you done?

> **[Learn Ignition at Your Own Pace](https://inductiveuniversity.com/)**
>
> Inductive University is a completely free online learning platform
> to help you learn Ignition by Inductive Automation®, the most powerful SCADA software in the world

---

<div class="post-metadata">

**Author:** ![nideyijuyidong](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@nideyijuyidong](https://forum.inductiveautomation.com/u/nideyijuyidong)\
**Post date:** [January 11, 2024, 2:40am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/5 "2024-01-11T02:40:59Z")

</div>

Usually, use tag historian to store value change. You can create a memory tag, and write the new value to the tag via system.tag.writeBlocking. But you may explain what is your complete function. There might be an easier way.  
As Transistor's say, If you never used a SCADA software, watch the videos first.

---

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [January 14, 2024, 11:22pm UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/6 "2024-01-14T23:22:34Z")

</div>

Id rather not make another topic if I can avoid it. What formatting error am I facing currently? I'm following the documentation and everything seems correct. I'm trying to on tag value change execute and insert query into the database.

Here's my current script.

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):  
if previousValue.value != currentValue.value and initialChange == False:  
parameters = {"param1": currentValue.value}  
system.db.runNamedQuery("Insert Cycle Time", parameters)

It's writing to a postgres database. Personal preference. I know the named query works this part isn't executing and I'm not sure why.

Any pointers?

---

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [January 15, 2024, 12:23am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/8 "2024-01-15T00:23:46Z")

</div>

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if previousValue.value != currentValue.value and initialChange == False:
		parameters = {"param1": currentValue.value}
		system.db.runNamedQuery("Insert Cycle Time", parameters)

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 15, 2024, 1:21am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/9 "2024-01-15T01:21:49Z")

</div>

There's a subtle difference in the `system.db.runNamedQuery` syntax depending on whether the function is being run in the Project Scope or in the Gateway Scope. You seem to be doing the latter so,

**Gateway Scope Syntax**

system.db.runNamedQuery( **project** , path, [parameters], [tx], [getKey])

I suspect that the script can't find your named query because that's defined in a project but the tag change event is independent of all projects.

[https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery](https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery)

---

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [January 15, 2024, 1:27am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/10 "2024-01-15T01:27:44Z")

</div>

Thank you for that, its now working as intended. Is there any easy way to know when something is project scope or gateway scope? I'm slowly going through the training and trying to apply what I'm learning to my current goal.

Thanks again

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 15, 2024, 1:32am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/11 "2024-01-15T01:32:35Z")

</div>

Project scope doesn’t exist. There is only:

- gateway
- client
- designer

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 15, 2024, 1:35am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/12 "2024-01-15T01:35:30Z")

</div>

I might be corrected on this but it should be:

- Tag events and anything programmed through the Project Browser → Scripting & Gateway Events (as the name suggests).
- Tag scripting. These are set up in Tag Editor → Scripting and the events include
  - value changed
  - quality changed
  - alarm active
  - alarm cleared
  - alarm acknowledged

Every other script will be executed in the scope of a project. e.g., A database save on button press, etc.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 15, 2024, 1:36am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/13 "2024-01-15T01:36:48Z")

</div>

> [@Kevin.Herron](#):
>
> Project scope doesn’t exist.

It does in the documentation, Kevin! (What are you doing manning the forum on a Sunday night?)

- Scope  
Vision Client, Perspective Session

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 15, 2024, 1:39am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/14 "2024-01-15T01:39:07Z")

</div>

AFAIK the only faux paus the documentation makes re: scope is pretending "Perspective Session" is something different than "Gateway".

But really, there's only 3 scopes of _execution_. Sometimes there is an implicit project and sometimes there isn't, but this isn't _scope_.

Scope can most simply be determined by asking yourself "which JVM is this code executing in?". There's only 3 possible answers:

- the one running the Gateway
- the one running the Client
- the one running the Designer

It's especially important that you understand "project scope" isn't a thing. You can write code in a project's script module and call it from any of the execution scopes.

The other thing that might catch somebody up is that some things belong to projects (script modules, named queries, etc...) and some don't (tags). When you write a tag event script and try to call a system function that relies on a resource defined in a project, then it either needs belong to project configured as the Gateway Scripting Project, or needs to be a call that takes an explicit project name.

---

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [January 15, 2024, 1:46am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/15 "2024-01-15T01:46:08Z")

</div>

So what is a better wording for this then?

It's from the 8.1 system.db.runNamedQuery Documentation

**Project Scope Syntax**

**system.db.runNamedQuery(path, [parameters], [tx], [getKey])**

- Parameters

String path - The path to the Named Query to run. Note that this is the full path to the query, including any folders.

Dictionary[String, Any] parameters - A Python dictionary of parameters for the Named Query to use. [optional]

String tx - An transaction ID, obtained from [beginNamedQueryTransaction](https://docs.inductiveautomation.com/display/DOC81/system.db.beginNamedQueryTransaction). If blank, will not be part of a transaction. [optional]

Boolean getKey - Only used for Update Query types. A flag indicating whether or not the result should be the number of rows affected (getKey=0) or the newly generated key value that was created as a result of the update (getKey=1). Not all databases support automatic retrieval of generated keys. [optional]

- Returns

Any - The results of the query. The exact object returned depends on the Query Type property of the Named Query: typically either a dataset when set to **Query** , an integer representing the number of rows affected when set to **Update Query** , or an object matching the data type of the value returned by a **Scalar Query**.

This feature was changed in Ignition version **8.1.29** :

PyDataset - The results of the Named Query as a PyDataset.

- Scope

Vision Client, Perspective Session

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 15, 2024, 1:49am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/16 "2024-01-15T01:49:10Z")

</div>

"Perspective Session" scope is basically Gateway scope with some extra contextual information available, notably a project. That's why you see the documentation split that function into 2 different calls with 2 different sets of arguments. Vision Client and Perspective Session have a project available as context.

In your case, a tag event script, there is no associated project because tags don't belong to projects. Tags do, however, execute in "Gateway" scope, which is you see a version of the function that requires you give it an explicit project name to find the named query in.

To some degree this is kind of just stuff you learn along the way.

---

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [January 15, 2024, 1:50am UTC](https://forum.inductiveautomation.com/t/question-on-configure-scripts/84090/17 "2024-01-15T01:50:55Z")

</div>

Thank you for that clarification.
