# Run Script Poll Rate

**URL:** <https://forum.inductiveautomation.com/t/run-script-poll-rate/8436>\
**Category:** Ignition\
**Created:** [May 12, 2014, 8:51am UTC](https://forum.inductiveautomation.com/t/run-script-poll-rate/8436 "2014-05-12T08:51:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidamcg](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@aidamcg](https://forum.inductiveautomation.com/u/aidamcg)\
**Post date:** [May 12, 2014, 8:51am UTC](https://forum.inductiveautomation.com/t/run-script-poll-rate/8436/1 "2014-05-12T08:51:56Z")

</div>

Hi

I have a run script in an expression for a SQL tag which seems to be executing at the scan class rate even though I have the poll rate set at 10 seconds. Is this what should happen or is there any way to prevent it from executing at the scan class rate. Attached is the trace history of select statements and the code I have running in the script.

```auto
runScript("system.db.runScalarQuery(\"SELECT State_Description FROM Machines_States WHERE Machine_ID = 3 AND State_ID = 20\",'PMON')",10000)
```

[attachment=0]Trace.txt[/attachment]

I have the same issue running a global script on a template which is the same select statement. I thought that it would run just once when the if condition was true but is running all the time. What I am doing on the template is querying what the state of a machine is when the PLC state is greater than 19 i.e. faulted state. I thought by using 0 it would behave like the now function. I tried putitng the poll rate at 10000 but it still runs all the time

`"<html><b><div align center>"+ {Coater.DataType::Machine_Name}+ "<br>"+{Coater.Multi-State Indicator.text} +" "+{Coater.DataType::LastChange.LastChangeTime} +"<br>"+
if({Coater.DataType::State} > 19 ,runScript("app.MachineState.MC_State("+{Coater.DataType::Machine_ID}+","+{Coater.DataType::State}+")",0),"")`  
Script Code

`def MC_State(Machine_ID,State_ID):
	import system
	strMC_ID = str(Machine_ID)
	strST_ID = str(State_ID)
	Data = system.db.runQuery("SELECT State_Description FROM Machines_States WHERE Machine_ID = " + strMC_ID + " AND State_ID = " + strST_ID)
	rowData = Data[0]
	State = rowData['State_Description']
	return State`

---

<div class="post-metadata">

**Author:** ![aidamcg](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@aidamcg](https://forum.inductiveautomation.com/u/aidamcg)\
**Post date:** [June 13, 2014, 9:18am UTC](https://forum.inductiveautomation.com/t/run-script-poll-rate/8436/2 "2014-06-13T09:18:18Z")

</div>

Hi

Wondering if there is a solution to the run script poll rate or is there some other work around I could employ to stop the script from executing all the time

Aidan

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 13, 2014, 7:33pm UTC](https://forum.inductiveautomation.com/t/run-script-poll-rate/8436/3 "2014-06-13T19:33:10Z")

</div>

Hi Aidan,

Did you try using a different scan class for the tag?
