# Global Variables Question

**URL:** <https://forum.inductiveautomation.com/t/global-variables-question/76229>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [July 11, 2023, 8:47pm UTC](https://forum.inductiveautomation.com/t/global-variables-question/76229 "2023-07-11T20:47:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_Gomez](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@Miguel\_Gomez](https://forum.inductiveautomation.com/u/Miguel_Gomez)\
**Post date:** [July 11, 2023, 8:47pm UTC](https://forum.inductiveautomation.com/t/global-variables-question/76229/1 "2023-07-11T20:47:59Z")

</div>

Hello all,

Just a question. I've been working in a Vision project but right now I have some doubts.

Currently the project works fine when I have the vision client active in the window where it update a database with some information when the propertyChange in a calendar changes each second and runs a query for saving data.

Right now is it necessary another window but when that new window is active in the vision client and the other is close the database stops saving data because it doesn't detect the change of the calendar.

I think right now I have to change my scripts with some global variables but I don't know how to do that. I just need that when Vision Client starts all my global variables start functioning no matter in what window the client is.

Thank you.

---

<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:** [July 11, 2023, 8:52pm UTC](https://forum.inductiveautomation.com/t/global-variables-question/76229/2 "2023-07-11T20:52:44Z")

</div>

It sounds as though you have not designed your application correctly. If you need something to record every second then you should set that up in the gateway, not in the application. That way it will run even if there is no client open.

[https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts](https://docs.inductiveautomation.com/display/DOC81/Gateway+Event+Scripts)

What are you trying to record? Is it PLC data from an OPC tag or something different?

---

<div class="post-metadata">

**Author:** ![Miguel\_Gomez](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@Miguel\_Gomez](https://forum.inductiveautomation.com/u/Miguel_Gomez)\
**Post date:** [July 11, 2023, 9:01pm UTC](https://forum.inductiveautomation.com/t/global-variables-question/76229/3 "2023-07-11T21:01:11Z")

</div>

> [@Transistor](#):
>
> It sounds as though you have not designed your application correctly. If you need something to record every second then you should set that up in the gateway, not in the application. That way it will run even if there is no client open.

Thank you, that was a new requirement and I'm new in ignition so I didn't project that this could be happen.

Yes I will record data from a PLC detecting the waterflow of some flow meters.

Thank you

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [July 11, 2023, 9:39pm UTC](https://forum.inductiveautomation.com/t/global-variables-question/76229/4 "2023-07-11T21:39:48Z")

</div>

Try enabling history on your flowmeter tags, it may get you what you want. If you want a set timing interval then maybe look at using transaction groups to log to a DB table.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 11, 2023, 9:41pm UTC](https://forum.inductiveautomation.com/t/global-variables-question/76229/5 "2023-07-11T21:41:31Z")

</div>

Transaction groups or tag history are absolutely the way to go here.

> **[Transaction Group Introduction Video at Inductive University](https://www.inductiveuniversity.com/videos/transaction-group-introduction/8.1)**
>
> What are Transaction Groups? They allow you to create simple bi-directional links between your PLCs and databases. With Transaction Groups you can perform tasks such as database to OPC synchronization, recipe management, and historical data logging.

> **[Configuring Tag History Video at Inductive University](https://www.inductiveuniversity.com/video/configuring-tag-history/8.1)**
>
> Tag History is a built-in way of saving historical data on a Tag to a database. Learn how to configure Tag history on a Tag from the Tag Editor.

---

<div class="post-metadata">

**Author:** ![Miguel\_Gomez](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@Miguel\_Gomez](https://forum.inductiveautomation.com/u/Miguel_Gomez)\
**Post date:** [July 11, 2023, 9:49pm UTC](https://forum.inductiveautomation.com/t/global-variables-question/76229/6 "2023-07-11T21:49:57Z")

</div>

Thank you, I'm going to work hard in this options and I will update you about the result.

Thank you again!

---

<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:** [July 11, 2023, 9:53pm UTC](https://forum.inductiveautomation.com/t/global-variables-question/76229/7 "2023-07-11T21:53:19Z")

</div>

> [@Miguel\_Gomez](#):
>
> Yes I will record data from a PLC detecting the waterflow of some flow meters.

Then

- Have the PLC count the pulses from the meter using a counter with a rollover of 1,000,000 or whatever you like.
- Read the PLC integer value with an OPC tag and set the scale factor in the tag properties.
- Use Ignition's built-in historian or a transaction group or gateway scheduled event to record the count. Note that this means that if you miss one or more readings that you will still be able to calculate the total flow and an average rate between any two timestamps.

Decide how often you need to take a reading and plan a sensible historian strategy.

---

<div class="post-metadata">

**Author:** ![Miguel\_Gomez](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@Miguel\_Gomez](https://forum.inductiveautomation.com/u/Miguel_Gomez)\
**Post date:** [July 12, 2023, 6:08am UTC](https://forum.inductiveautomation.com/t/global-variables-question/76229/8 "2023-07-12T06:08:05Z")

</div>

Thank you!

Well right now I configured a New Gateway Schedule Script, each minute the data is saved in the data base. I don't have the PLC right now so I used a Tag with random values to simulate the flow

```auto
def onScheduledEvent():
	time0 = system.date.now()
	tagValuesL1 = system.tag.readBlocking(['[Sample_Tags]Random/RandomDouble1'])
	valueL1 = tagValuesL1[0].value
	flowmeterL1 = "LFM1"
	parameters = {"date":time0, "value":valueL1,"flowmeter":flowmeterL1} 
	system.db.runNamedQuery("Insert Data", parameters)

	tagValuesL2 = system.tag.readBlocking(['[Sample_Tags]Random/RandomDouble2'])
	valueL2 = tagValuesL2[0].value
	flowmeterL2 = "LFM2"
	parameters2 = {"date":time0, "value":valueL2,"flowmeter":flowmeterL2} 
	system.db.runNamedQuery("Insert Data", parameters2)

```

With this I can save the data at the moment the gateway is started and it is not necessary to open Vision or perspective.

Thank you for all your help 😃

---

<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:** [July 12, 2023, 6:14am UTC](https://forum.inductiveautomation.com/t/global-variables-question/76229/9 "2023-07-12T06:14:31Z")

</div>

Create another test tag and create an event to read that and write back the value + random increment. That will give you a test "meter" to read with ever-increasing count.

You need to consider what will happen if the meter rolls over.

---

<div class="post-metadata">

**Author:** ![Miguel\_Gomez](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@Miguel\_Gomez](https://forum.inductiveautomation.com/u/Miguel_Gomez)\
**Post date:** [July 12, 2023, 6:20am UTC](https://forum.inductiveautomation.com/t/global-variables-question/76229/10 "2023-07-12T06:20:41Z")

</div>

Thank you, I will!

I'm learning and surely I will be asking many more questions in this forum and I hope some day help people too!
