# Gateway Timer script not working

**URL:** <https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519>\
**Category:** Ignition\
**Tags:** ignition80, scripting\
**Created:** [February 24, 2022, 3:31pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519 "2022-02-24T15:31:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepak.nule](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@deepak.nule](https://forum.inductiveautomation.com/u/deepak.nule)\
**Post date:** [February 24, 2022, 3:31pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519/1 "2022-02-24T15:31:41Z")

</div>

I have script to post data to web services-

Using Gateway timer script runs, But scripts failing sometimes using timer ,whereas using user button they work 100%.  
Any solution or improvement we can do.

Sample code-

```auto
TS1=system.date.addMinutes((system.date.now()),-15);
TS2=system.date.addMinutes((system.date.now()),-1);

SPC_dict={};
QC_List=[];
SPC_QC=system.db.runPrepQuery("SELECT X1,X2,X3,X4,X5,.....X10 MasterData where TS>? and TS<=?",[TS1,TS2],'SPCD');

#by iterations data converted to dictionary and posting single data point of dict using loop

 dict1={};#key values will be in dictionary
 
 POS=(system.util.jsonEncode(dict1));
 PlantCode='XXXX';
 InputDataJson=POS;
 id=(SPC_QC.getValueAt(int(j),12));
 response=system.ws.runWebService("TO_PRODUCTION",
 { 
 'PlantCode':PlantCode,
 'InputDataJson':InputDataJson
 },
 None,
 None)
	
 msg=(response.getChild("Rowsets").getChild("Rowset").getChild("Row").getChild("outputMessage").getValue())
 if(msg=='Success!!'):
  system.db.runPrepUpdate("UPDATE MasterData SET POST_STATUS=1 where IDNum=?", [id], 'DB1');

 else:
  system.db.runPrepUpdate("UPDATE MasterData SET POST_STATUS=0 where IDNum=?", [id], 'DB1')

```

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 24, 2022, 3:33pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519/2 "2022-02-24T15:33:14Z")

</div>

What error are you getting in your server logs? If it’s not working the gateway the errors are being logged. What do you see?

---

<div class="post-metadata">

**Author:** ![deepak.nule](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@deepak.nule](https://forum.inductiveautomation.com/u/deepak.nule)\
**Post date:** [February 24, 2022, 3:35pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519/3 "2022-02-24T15:35:45Z")

</div>

I don’t see any error in gateway logs, Even we have some event based script to perform posting every 10 sec or 1 minute (event occurs).

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 24, 2022, 3:36pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519/4 "2022-02-24T15:36:51Z")

</div>

So how do you know this is failing exactly? What is not happening for you that you are expecting to happen?

---

<div class="post-metadata">

**Author:** ![deepak.nule](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@deepak.nule](https://forum.inductiveautomation.com/u/deepak.nule)\
**Post date:** [February 24, 2022, 3:40pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519/5 "2022-02-24T15:40:15Z")

</div>

If few data points not posted successfully, I can see them on table(as failed post).  
Using same gateway script On button event I can reprocess all failed data points.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 24, 2022, 3:46pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519/6 "2022-02-24T15:46:44Z")

</div>

Oh I see this is a SepaSoft function. Though some people here are familiar with it, you may get better help contacting their support team directly.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [February 24, 2022, 6:19pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519/7 "2022-02-24T18:19:52Z")

</div>

I don’t see how that is gonna work. `j` is not defined

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 24, 2022, 6:22pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519/8 "2022-02-24T18:22:28Z")

</div>

On this note - put your entire function into a script library and call it from your button press/gateway event script to ensure the exact same code is running.

I see also your query looks odd as there is no `FROM` keyword in it so I don’t know if you copied things over and modified them to hide certain things or if that’s a actual typo in your real code etc.

Also in python just so you know you don’t have to end your lines with a `;`

---

<div class="post-metadata">

**Author:** ![deepak.nule](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@deepak.nule](https://forum.inductiveautomation.com/u/deepak.nule)\
**Post date:** [February 25, 2022, 3:27am UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519/9 "2022-02-25T03:27:34Z")

</div>

Yes Its not complete code ,as it executes without any error. Question is why few executions didn’t happen(timer based gateway script )

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [February 25, 2022, 3:40am UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519/10 "2022-02-25T03:40:16Z")

</div>

If you think scripts should work always no matter the scope, I’m afraid you’re wrong. That would be my answer to your question.  
Since you don’t post further info, I doubt someone can help, likely speculate 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [February 25, 2022, 1:33pm UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519/11 "2022-02-25T13:33:35Z")

</div>

For example one common issue going from a client script to gateway script is that in a vision client you don’t have to specify which database you are using and the default database for the project will be used but in the gateway context you must provide the database.

---

<div class="post-metadata">

**Author:** ![deepak.nule](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@deepak.nule](https://forum.inductiveautomation.com/u/deepak.nule)\
**Post date:** [February 28, 2022, 2:46am UTC](https://forum.inductiveautomation.com/t/gateway-timer-script-not-working/56519/12 "2022-02-28T02:46:26Z")

</div>

resolved by using shared option
